-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimatedModal.js
80 lines (75 loc) · 3.05 KB
/
animatedModal.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, {useEffect, useRef} from 'react';
import Lottie from 'lottie-react-native';
import {Modal, StyleSheet, Text, TouchableOpacity, View} from "react-native";
const LottieModal = (props) => {
const animationRef = useRef(null)
useEffect(() => {
animationRef.current?.play()
}, [])
const size = 'size' in props ? props.size : 150
return (
<Modal
animationType="fade"
transparent={true}
visible={true}
>
<TouchableOpacity style={[styles.modalBackDrop, {backgroundColor: 'bgColor' in props ? props.bgColor : 'rgba(0, 0, 0, 0.5)'}]} activeOpacity={1} onPress={() => props.hideModal()}>
<View style={styles.centeredView}>
<View style={styles.modalTransView}>
{'lottieSource' in props ? <Lottie
ref={animationRef}
style={{width: size, height: size}}
source={props.lottieSource}
autoPlay={'autoPlay' in props ? props.autoPlay : true}
autoSize={'autoSize' in props ? props.autoSize : false}
loop={'loop' in props ? props.loop : false}
onAnimationFinish={() => {
setTimeout(() => {
props.hideModal()
}, 'timeout' in props ? props.timeout : 0)
}}
/> : null}
{'title' in props ?
<Text style={{color: '#fff', fontWeight: 'bold'}}>{props.title}</Text> : null}
{'message' in props ?
<Text style={{
color: '#fff',
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center',
textAlign: 'center',
}}>{props.message}</Text> : null}
<Text style={{
color: '#b9b9b9',
marginTop: 20,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center',
textAlign: 'center',
fontSize: 10,
}}>{'dismissText' in props ? props.dismissText : 'Click anywhere to dismiss'}</Text>
</View>
</View>
</TouchableOpacity>
</Modal>
);
}
export default LottieModal;
const styles = StyleSheet.create({
modalBackDrop: {
flex: 1
},
centeredView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginTop: 22,
},
modalTransView: {
margin: 20,
elevation: 5,
padding: 35,
alignItems: 'center',
backgroundColor: 'transparent',
},
});