Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/CustomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Props = {
onClose?: () => void;
/** 閉じるアニメーションが完了した後に呼ばれるコールバック */
onCloseAnimationEnd?: () => void;
/** 開くアニメーションが完了した後に呼ばれるコールバック */
onShow?: () => void;
dismissOnBackdropPress?: boolean;
backdropStyle?: StyleProp<ViewStyle>;
containerStyle?: StyleProp<ViewStyle>;
Expand All @@ -39,6 +41,7 @@ export const CustomModal: React.FC<Props> = ({
children,
onClose,
onCloseAnimationEnd,
onShow,
dismissOnBackdropPress = true,
backdropStyle,
containerStyle,
Expand Down Expand Up @@ -72,7 +75,11 @@ export const CustomModal: React.FC<Props> = ({
toValue: 1,
duration: animationDuration,
useNativeDriver: true,
}).start();
}).start(({ finished }) => {
if (finished) {
onShow?.();
}
});
return;
}

Expand All @@ -86,7 +93,7 @@ export const CustomModal: React.FC<Props> = ({
onCloseAnimationEnd?.();
}
});
}, [animationDuration, opacity, visible, onCloseAnimationEnd]);
}, [animationDuration, opacity, visible, onCloseAnimationEnd, onShow]);

const handleBackdropPress = () => {
Keyboard.dismiss();
Expand Down
15 changes: 7 additions & 8 deletions src/components/SavePresetNameModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ export const SavePresetNameModal: React.FC<Props> = ({
);
inboundOpacity.setValue(1);
outboundOpacity.setValue(1);

// モーダルアニメーション(180ms)とKeyboardAvoidingViewのレイアウト確定を待ってからフォーカスする
if (Platform.OS === 'ios') {
const timer = setTimeout(() => {
textInputRef.current?.focus();
}, 300);
return () => clearTimeout(timer);
}
}
}, [visible, defaultName, directionOptions, inboundOpacity, outboundOpacity]);

Expand Down Expand Up @@ -163,6 +155,12 @@ export const SavePresetNameModal: React.FC<Props> = ({
onSubmit(name, selectedDirection);
}, [onSubmit, selectedDirection, hasDirectionOptions]);

const handleShow = useCallback(() => {
if (Platform.OS === 'ios') {
textInputRef.current?.focus();
}
}, []);

const canSubmit =
!isEmpty && (!hasDirectionOptions || selectedDirection !== null);
const textColor = isLEDTheme ? '#fff' : '#000';
Expand All @@ -171,6 +169,7 @@ export const SavePresetNameModal: React.FC<Props> = ({
<CustomModal
visible={visible}
onClose={onClose}
onShow={handleShow}
backdropStyle={{ backgroundColor: 'rgba(0,0,0,0.5)' }}
contentContainerStyle={[
styles.contentView,
Expand Down
Loading