Преглед изворни кода

fix: css animation trigger animation start and end on mount

代强 пре 3 година
родитељ
комит
d0fbd5a475
1 измењених фајлова са 11 додато и 3 уклоњено
  1. 11 3
      packages/semi-ui/_cssAnimation/index.tsx

+ 11 - 3
packages/semi-ui/_cssAnimation/index.tsx

@@ -1,5 +1,5 @@
-import React, {CSSProperties, ReactNode} from 'react';
-import {isEqual, noop} from "lodash";
+import React, { CSSProperties, ReactNode } from 'react';
+import { isEqual, noop } from "lodash";
 
 
 
 
 interface AnimationEventsNeedBind {
 interface AnimationEventsNeedBind {
@@ -50,6 +50,14 @@ class CSSAnimation extends React.Component<AnimationProps, AnimationState> {
     }
     }
 
 
 
 
+    componentDidMount() {
+        this.props.onAnimationStart?.();
+        if (!this.props.motion){
+            this.props.onAnimationEnd?.();
+        }
+    }
+
+
     componentDidUpdate(prevProps: Readonly<AnimationProps>, prevState: Readonly<AnimationState>, snapshot?: any) {
     componentDidUpdate(prevProps: Readonly<AnimationProps>, prevState: Readonly<AnimationState>, snapshot?: any) {
         const changedKeys = Object.keys(this.props).filter(key => !isEqual(this.props[key], prevProps[key]));
         const changedKeys = Object.keys(this.props).filter(key => !isEqual(this.props[key], prevProps[key]));
         if (changedKeys.includes("animationState")) {
         if (changedKeys.includes("animationState")) {
@@ -103,7 +111,7 @@ class CSSAnimation extends React.Component<AnimationProps, AnimationState> {
                 animationStyle: {},
                 animationStyle: {},
                 animationEventsNeedBind: {},
                 animationEventsNeedBind: {},
                 isAnimating: this.state.isAnimating
                 isAnimating: this.state.isAnimating
-            })
+            });
         }
         }
     }
     }
 }
 }