1
0
Эх сурвалжийг харах

Merge pull request #1217 from DouyinFE/fix_modal_afterClose

fix: fix modal afterClose exec time
代强 3 жил өмнө
parent
commit
a6e6eb89ec

+ 8 - 8
packages/semi-ui/modal/Modal.tsx

@@ -188,10 +188,10 @@ class Modal extends BaseComponent<ModalReactProps, ModalState> {
         if (props.visible && prevState.displayNone) {
             newState.displayNone = false;
         }
-
-        if (!props.visible && !props.motion && !prevState.displayNone) {
-            newState.displayNone = true;
-        }
+        //
+        // if (!props.visible && !props.motion && !prevState.displayNone) {
+        //     newState.displayNone = true;
+        // }
 
 
         return newState;
@@ -250,15 +250,15 @@ class Modal extends BaseComponent<ModalReactProps, ModalState> {
         if (!prevProps.visible && this.props.visible) {
             this.foundation.beforeShow();
         }
-        // show => hide
-        if (prevProps.visible && !this.props.visible) {
-            this.foundation.afterHide();
-        }
 
         const shouldRender = this.props.visible || (this.props.keepDOM && (!this.props.lazyRender || this._haveRendered));
         if (shouldRender === true && this.state.shouldRender === false) {
             this.foundation.setShouldRender(true);
         }
+
+        if (!prevState.displayNone && this.state.displayNone){
+            this.foundation.afterHide();
+        }
     }
 
     componentWillUnmount() {

+ 6 - 21
packages/semi-ui/modal/useModal/HookModal.tsx

@@ -1,12 +1,10 @@
 import React, { PropsWithChildren } from 'react';
 import ConfirmModal from '../ConfirmModal';
-import { get } from 'lodash';
 import { ConfirmProps } from '../confirm';
 
 interface HookModalProps {
     afterClose: (...args: any[]) => void;
-    config: ConfirmProps;
-    motion?: boolean
+    config: ConfirmProps
 }
 
 export interface HookModalRef {
@@ -33,28 +31,15 @@ const HookModal = ({ afterClose, config, ...props }: PropsWithChildren<HookModal
         },
     }));
 
-    const { motion } = props;
-    /* istanbul ignore next */
-    const mergedMotion =
-        typeof motion === 'undefined' || motion ?
-            {
-                ...(motion as any),
-                didLeave: (...args: any[]) => {
-                    const didLeave = get(props.motion, 'didLeave');
-
-                    if (typeof didLeave === 'function') {
-                        didLeave(...args);
-                    }
-                    afterClose();
-                },
-            } :
-            false;
-
+    const mergeAfterClose = () => {
+        config?.afterClose?.();
+        afterClose();
+    }; 
     return (
         <ConfirmModal
             {...innerConfig}
+            afterClose={mergeAfterClose}
             // visible={!visible ? visible : undefined}
-            motion={mergedMotion}
         />
     );
 };