Skip to content

Commit 9b4362a

Browse files
committed
chore(Modal): 修复因props改变就会走一遍动画的问题 (#277)
1 parent 97bbf43 commit 9b4362a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

packages/core/src/Modal/index.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ export default (props: ModalProps = {}) => {
2828
setLayoutWidth(width);
2929
}
3030
}
31-
function getTransformSize() {
32-
if (placement === 'top') {
33-
return -layoutHeight;
34-
}
35-
if (placement === 'bottom') {
36-
return layoutHeight;
37-
}
38-
if (placement === 'left') {
39-
return -layoutWidth;
40-
}
41-
if (placement === 'right') {
42-
return layoutWidth;
43-
}
44-
return 0;
45-
}
31+
4632
useMemo(() => {
33+
function getTransformSize() {
34+
if (placement === 'top') {
35+
return -layoutHeight;
36+
}
37+
if (placement === 'bottom') {
38+
return layoutHeight;
39+
}
40+
if (placement === 'left') {
41+
return -layoutWidth;
42+
}
43+
if (placement === 'right') {
44+
return layoutWidth;
45+
}
46+
return 0;
47+
}
4748
const result = getTransformSize();
4849
if (!result) return;
4950
if (visible) {
@@ -73,7 +74,7 @@ export default (props: ModalProps = {}) => {
7374
]).start();
7475
}
7576
// eslint-disable-next-line react-hooks/exhaustive-deps
76-
}, [visible, getTransformSize]);
77+
}, [visible, layoutHeight, layoutWidth]);
7778
const translateStyle = {} as {
7879
translateY: Animated.Value;
7980
translateX: Animated.Value;

0 commit comments

Comments
 (0)