forked from xcarpentier/react-native-country-picker-modal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatedModal.tsx
52 lines (43 loc) · 978 Bytes
/
AnimatedModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as React from 'react'
import { Animated, Dimensions, StyleSheet } from 'react-native'
const { height } = Dimensions.get('window')
const duration = 300
const useNativeDriver = true
interface Props {
visible?: boolean
children: React.ReactNode
}
export const AnimatedModal = ({ children, visible }: Props) => {
const translateY = new Animated.Value(height)
const showModal = Animated.timing(translateY, {
toValue: 0,
duration,
useNativeDriver,
}).start
const hideModal = Animated.timing(translateY, {
toValue: height,
duration,
useNativeDriver,
}).start
React.useEffect(() => {
if (visible) {
showModal()
} else {
hideModal()
}
}, [visible])
return (
<Animated.View
style={{
...StyleSheet.absoluteFillObject,
transform: [{ translateY }],
zIndex: 99,
}}
>
{children}
</Animated.View>
)
}
AnimatedModal.defaultProps = {
visible: false,
}