Skip to content

Commit b590932

Browse files
TinyKittenclaude
andcommitted
onShow/onCloseAnimationEndをrefパターンに変更し不要なエフェクト再実行を防止
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f535e27 commit b590932

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/CustomModal.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export const CustomModal: React.FC<Props> = ({
5252
}) => {
5353
const [isMounted, setIsMounted] = useState(visible);
5454
const opacity = useRef(new Animated.Value(visible ? 1 : 0)).current;
55+
const onShowRef = useRef(onShow);
56+
const onCloseAnimationEndRef = useRef(onCloseAnimationEnd);
5557
const isLEDTheme = useAtomValue(isLEDThemeAtom);
5658
const animatedBackdropStyle = {
5759
opacity,
@@ -68,6 +70,14 @@ export const CustomModal: React.FC<Props> = ({
6870
],
6971
};
7072

73+
useEffect(() => {
74+
onShowRef.current = onShow;
75+
}, [onShow]);
76+
77+
useEffect(() => {
78+
onCloseAnimationEndRef.current = onCloseAnimationEnd;
79+
}, [onCloseAnimationEnd]);
80+
7181
useEffect(() => {
7282
if (visible) {
7383
setIsMounted(true);
@@ -77,7 +87,7 @@ export const CustomModal: React.FC<Props> = ({
7787
useNativeDriver: true,
7888
}).start(({ finished }) => {
7989
if (finished) {
80-
onShow?.();
90+
onShowRef.current?.();
8191
}
8292
});
8393
return;
@@ -90,10 +100,10 @@ export const CustomModal: React.FC<Props> = ({
90100
}).start(({ finished }) => {
91101
if (finished && !visible) {
92102
setIsMounted(false);
93-
onCloseAnimationEnd?.();
103+
onCloseAnimationEndRef.current?.();
94104
}
95105
});
96-
}, [animationDuration, opacity, visible, onCloseAnimationEnd, onShow]);
106+
}, [animationDuration, opacity, visible]);
97107

98108
const handleBackdropPress = () => {
99109
Keyboard.dismiss();

0 commit comments

Comments
 (0)