-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathindex.js
94 lines (85 loc) · 2.18 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react';
import { StyleSheet, View, Modal } from 'react-native';
import PropTypes from 'prop-types';
import LottieAnimation from 'lottie-react-native';
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
export default class AnimatedLoader extends React.PureComponent {
static defaultProps = {
visible: false,
overlayColor: 'rgba(0, 0, 0, 0.25)',
animationType: 'none',
source: require('./loader.json'),
animationStyle: {},
speed: 1,
loop: true,
};
static propTypes = {
visible: PropTypes.bool,
overlayColor: PropTypes.string,
animationType: PropTypes.oneOf(['none', 'slide', 'fade']),
source: PropTypes.object,
animationStyle: ViewPropTypes.style,
speed: PropTypes.number,
loop: PropTypes.bool,
};
animation = React.createRef();
componentDidMount() {
if (this.animation.current) {
this.animation.current.play();
}
}
componentDidUpdate(prevProps) {
const { visible } = this.props;
if (visible !== prevProps.visible) {
if (this.animation.current) {
this.animation.current.play();
}
}
}
_renderLottie = () => {
const { source, animationStyle, speed, loop } = this.props;
return (
<LottieAnimation
ref={this.animation}
source={source}
loop={loop}
speed={speed}
style={[styles.animationStyle, animationStyle]}
/>
);
};
render() {
const { visible, overlayColor, animationType } = this.props;
return (
<Modal
transparent
visible={visible}
animationType={animationType}
supportedOrientations={['portrait']}
onRequestClose={() => {}}
>
<View style={[styles.container, { backgroundColor: overlayColor }]}>
<View>{this._renderLottie()}</View>
{this.props.children}
</View>
</Modal>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'transparent',
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
alignItems: 'center',
justifyContent: 'center',
},
animationStyle: {
height: '100%',
width: '100%',
},
});