@@ -7,16 +7,16 @@ import {
7
7
watch ,
8
8
onMounted ,
9
9
getCurrentInstance ,
10
+ computed ,
10
11
onUnmounted ,
12
+ onUpdated ,
11
13
} from 'vue' ;
12
14
import PropTypes from '../_util/vue-types' ;
13
15
import classNames from '../_util/classNames' ;
14
16
import omit from 'omit.js' ;
15
17
import ResizeObserver from '../vc-resize-observer' ;
16
- // import BaseMixin from '../_util/BaseMixin';
17
18
import throttleByAnimationFrame from '../_util/throttleByAnimationFrame' ;
18
19
import { defaultConfigProvider } from '../config-provider' ;
19
- import warning from '../_util/warning' ;
20
20
import { withInstall } from '../_util/type' ;
21
21
import {
22
22
addObserveTarget ,
@@ -76,36 +76,19 @@ const Affix = defineComponent({
76
76
} ) ;
77
77
const currentInstance = getCurrentInstance ( ) ;
78
78
79
- const getOffsetTop = ( ) => {
80
- const { offset, offsetBottom } = props ;
81
- let { offsetTop } = props ;
82
- if ( offsetTop === undefined ) {
83
- offsetTop = offset ;
84
- warning (
85
- offset === undefined ,
86
- 'Affix' ,
87
- '`offset` is deprecated. Please use `offsetTop` instead.' ,
88
- ) ;
89
- }
90
-
91
- if ( offsetBottom === undefined && offsetTop === undefined ) {
92
- offsetTop = 0 ;
93
- }
94
- return offsetTop ;
95
- } ;
96
- const getOffsetBottom = ( ) => {
97
- return props . offsetBottom ;
98
- } ;
79
+ const offsetTop = computed ( ( ) => {
80
+ return props . offsetBottom === undefined && props . offsetTop === undefined
81
+ ? 0
82
+ : props . offsetTop ;
83
+ } ) ;
84
+ const offsetBottom = computed ( ( ) => props . offsetBottom ) ;
99
85
const measure = ( ) => {
100
86
const { status, lastAffix } = state ;
101
87
const { target } = props ;
102
88
if ( status !== AffixStatus . Prepare || ! fixedNode . value || ! placeholderNode . value || ! target ) {
103
89
return ;
104
90
}
105
91
106
- const offsetTop = getOffsetTop ( ) ;
107
- const offsetBottom = getOffsetBottom ( ) ;
108
-
109
92
const targetNode = target ( ) ;
110
93
if ( ! targetNode ) {
111
94
return ;
@@ -116,8 +99,8 @@ const Affix = defineComponent({
116
99
} as AffixState ;
117
100
const targetRect = getTargetRect ( targetNode ) ;
118
101
const placeholderReact = getTargetRect ( placeholderNode . value as HTMLElement ) ;
119
- const fixedTop = getFixedTop ( placeholderReact , targetRect , offsetTop ) ;
120
- const fixedBottom = getFixedBottom ( placeholderReact , targetRect , offsetBottom ) ;
102
+ const fixedTop = getFixedTop ( placeholderReact , targetRect , offsetTop . value ) ;
103
+ const fixedBottom = getFixedBottom ( placeholderReact , targetRect , offsetBottom . value ) ;
121
104
if ( fixedTop !== undefined ) {
122
105
newState . affixStyle = {
123
106
position : 'fixed' ,
@@ -155,6 +138,7 @@ const Affix = defineComponent({
155
138
affixStyle : undefined ,
156
139
placeholderStyle : undefined ,
157
140
} ) ;
141
+ currentInstance . update ( ) ;
158
142
// Test if `updatePosition` called
159
143
if ( process . env . NODE_ENV === 'test' ) {
160
144
emit ( 'testUpdatePosition' ) ;
@@ -170,16 +154,12 @@ const Affix = defineComponent({
170
154
171
155
// Check position change before measure to make Safari smooth
172
156
if ( target && affixStyle ) {
173
- const offsetTop = getOffsetTop ( ) ;
174
- const offsetBottom = getOffsetBottom ( ) ;
175
-
176
157
const targetNode = target ( ) ;
177
158
if ( targetNode && placeholderNode . value ) {
178
159
const targetRect = getTargetRect ( targetNode ) ;
179
160
const placeholderReact = getTargetRect ( placeholderNode . value as HTMLElement ) ;
180
- const fixedTop = getFixedTop ( placeholderReact , targetRect , offsetTop ) ;
181
- const fixedBottom = getFixedBottom ( placeholderReact , targetRect , offsetBottom ) ;
182
-
161
+ const fixedTop = getFixedTop ( placeholderReact , targetRect , offsetTop . value ) ;
162
+ const fixedBottom = getFixedBottom ( placeholderReact , targetRect , offsetBottom . value ) ;
183
163
if (
184
164
( fixedTop !== undefined && affixStyle . top === fixedTop ) ||
185
165
( fixedBottom !== undefined && affixStyle . bottom === fixedBottom )
@@ -215,13 +195,6 @@ const Affix = defineComponent({
215
195
} ,
216
196
) ;
217
197
watch ( ( ) => [ props . offsetTop , props . offsetBottom ] , updatePosition ) ;
218
- watch (
219
- ( ) => state . status ,
220
- ( ) => {
221
- measure ( ) ;
222
- } ,
223
- ) ;
224
-
225
198
onMounted ( ( ) => {
226
199
const { target } = props ;
227
200
if ( target ) {
@@ -234,7 +207,9 @@ const Affix = defineComponent({
234
207
} ) ;
235
208
}
236
209
} ) ;
237
-
210
+ onUpdated ( ( ) => {
211
+ measure ( ) ;
212
+ } ) ;
238
213
onUnmounted ( ( ) => {
239
214
clearTimeout ( state . timeout ) ;
240
215
removeObserveTarget ( currentInstance ) ;
0 commit comments