refactor: close animation

This commit is contained in:
Jakub Grzywacz 2021-07-10 15:55:01 +02:00
parent af342a86f9
commit 095a1fda25
No known key found for this signature in database
GPG Key ID: 5BBB685871FF63C4

View File

@ -23,24 +23,31 @@ export const ModalWithBackdrop = ({
children, children,
}: ModalWithBackdropProps) => { }: ModalWithBackdropProps) => {
const { height: screenHeight } = useWindowDimensions(); const { height: screenHeight } = useWindowDimensions();
const translateY = React.useRef(new Animated.Value(0)).current; const translateY = React.useRef(new Animated.Value(screenHeight)).current;
const ctx = React.useContext(KeyboardContext); const ctx = React.useContext(KeyboardContext);
React.useEffect(() => { React.useEffect(() => {
Animated.timing(translateY, { Animated.spring(translateY, {
toValue: isOpen ? 0 : screenHeight, toValue: isOpen ? 0 : screenHeight,
useNativeDriver: true, useNativeDriver: true,
duration: 500,
}).start(); }).start();
}, [isOpen, screenHeight, translateY]); }, [isOpen, screenHeight, translateY]);
const handleClose = () => {
Animated.spring(translateY, {
toValue: screenHeight,
useNativeDriver: true,
}).start();
setTimeout(() => backdropPress(), 200);
};
return ( return (
<Modal visible={isOpen} animationType="fade" transparent={true}> <Modal visible={isOpen} animationType="fade" transparent={true}>
<GestureHandlerRootView style={styles.modalContainer}> <GestureHandlerRootView style={styles.modalContainer}>
<TouchableOpacity <TouchableOpacity
style={styles.modalContainer} style={styles.modalContainer}
activeOpacity={1} activeOpacity={1}
onPress={backdropPress} onPress={handleClose}
> >
<View <View
style={[ style={[