@@ -21,6 +21,7 @@ import { getMotion } from './utils/legacyUtil';
2121 * Popup should follow the steps for each component work correctly:
2222 * measure - check for the current stretch size
2323 * align - let component align the position
24+ * aligned - re-align again in case additional className changed the size
2425 * afterAlign - choice next step is trigger motion or finished
2526 * beforeMotion - should reset motion to invisible so that CSSMotion can do normal motion
2627 * motion - play the motion
@@ -30,6 +31,7 @@ type PopupStatus =
3031 | null
3132 | 'measure'
3233 | 'align'
34+ | 'aligned'
3335 | 'afterAlign'
3436 | 'beforeMotion'
3537 | 'motion'
@@ -157,7 +159,7 @@ class Popup extends Component<PopupProps, PopupState> {
157159
158160 default : {
159161 // Go to next status
160- const queue : PopupStatus [ ] = [ 'measure' , 'align' , 'afterAlign' , 'beforeMotion' , 'motion' ] ;
162+ const queue : PopupStatus [ ] = [ 'measure' , 'align' , null , 'beforeMotion' , 'motion' ] ;
161163 const index = queue . indexOf ( status ) ;
162164 const nextStatus = queue [ index + 1 ] ;
163165 if ( nextStatus ) {
@@ -184,10 +186,20 @@ class Popup extends Component<PopupProps, PopupState> {
184186 }
185187
186188 onAlign = ( popupDomNode : HTMLElement , align : AlignType ) => {
189+ const { status } = this . state ;
187190 const { getClassNameFromAlign, onAlign } = this . props ;
188191 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+ }
191203 } ;
192204
193205 onMotionEnd = ( ) => {
@@ -289,7 +301,8 @@ class Popup extends Component<PopupProps, PopupState> {
289301 }
290302
291303 // ================== Align ==================
292- const mergedAlignDisabled = ! visible || ( status !== 'align' && status !== 'stable' ) ;
304+ const mergedAlignDisabled =
305+ ! visible || ( status !== 'align' && status !== 'aligned' && status !== 'stable' ) ;
293306
294307 // ================== Popup ==================
295308 let mergedPopupVisible = true ;
0 commit comments