@@ -21,6 +21,7 @@ import { getMotion } from './utils/legacyUtil';
21
21
* Popup should follow the steps for each component work correctly:
22
22
* measure - check for the current stretch size
23
23
* align - let component align the position
24
+ * aligned - re-align again in case additional className changed the size
24
25
* afterAlign - choice next step is trigger motion or finished
25
26
* beforeMotion - should reset motion to invisible so that CSSMotion can do normal motion
26
27
* motion - play the motion
@@ -30,6 +31,7 @@ type PopupStatus =
30
31
| null
31
32
| 'measure'
32
33
| 'align'
34
+ | 'aligned'
33
35
| 'afterAlign'
34
36
| 'beforeMotion'
35
37
| 'motion'
@@ -157,7 +159,7 @@ class Popup extends Component<PopupProps, PopupState> {
157
159
158
160
default : {
159
161
// Go to next status
160
- const queue : PopupStatus [ ] = [ 'measure' , 'align' , 'afterAlign' , 'beforeMotion' , 'motion' ] ;
162
+ const queue : PopupStatus [ ] = [ 'measure' , 'align' , null , 'beforeMotion' , 'motion' ] ;
161
163
const index = queue . indexOf ( status ) ;
162
164
const nextStatus = queue [ index + 1 ] ;
163
165
if ( nextStatus ) {
@@ -184,10 +186,20 @@ class Popup extends Component<PopupProps, PopupState> {
184
186
}
185
187
186
188
onAlign = ( popupDomNode : HTMLElement , align : AlignType ) => {
189
+ const { status } = this . state ;
187
190
const { getClassNameFromAlign, onAlign } = this . props ;
188
191
const alignClassName = getClassNameFromAlign ( align ) ;
189
- this . setState ( { alignClassName } ) ;
190
- onAlign ( popupDomNode , align ) ;
192
+
193
+ if ( status === 'align' ) {
194
+ this . setState ( { alignClassName, status : 'aligned' } , ( ) => {
195
+ this . alignRef . current . forceAlign ( ) ;
196
+ } ) ;
197
+ } else if ( status === 'aligned' ) {
198
+ this . setState ( { alignClassName, status : 'afterAlign' } ) ;
199
+ onAlign ( popupDomNode , align ) ;
200
+ } else {
201
+ this . setState ( { alignClassName } ) ;
202
+ }
191
203
} ;
192
204
193
205
onMotionEnd = ( ) => {
@@ -289,7 +301,8 @@ class Popup extends Component<PopupProps, PopupState> {
289
301
}
290
302
291
303
// ================== Align ==================
292
- const mergedAlignDisabled = ! visible || ( status !== 'align' && status !== 'stable' ) ;
304
+ const mergedAlignDisabled =
305
+ ! visible || ( status !== 'align' && status !== 'aligned' && status !== 'stable' ) ;
293
306
294
307
// ================== Popup ==================
295
308
let mergedPopupVisible = true ;
0 commit comments