-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
126 lines (113 loc) · 2.79 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React from 'react';
import { Dimensions, StyleSheet, View, Modal, ViewPropTypes, Text } from 'react-native';
import { arrayOf, bool, object, oneOf, number, string } from 'prop-types';
import LottieAnimation from 'lottie-react-native';
const WIDTH = Dimensions.get('window').width;
const TRANSLUCENT_COLOR = 'rgba(0,0,0,.7)';
const TEXT_COLOR = '#ffffff';
const styles = StyleSheet.create({
animationStyle: {
alignSelf: 'center',
height: (WIDTH / 100) * 30,
width: (WIDTH / 100) * 30,
},
container: {
alignItems: 'center',
backgroundColor: TRANSLUCENT_COLOR,
bottom: 0,
flex: 1,
justifyContent: 'center',
left: 0,
position: 'absolute',
right: 0,
top: 0,
},
textStyle: {
alignSelf: 'center',
color: TEXT_COLOR,
fontSize: 16,
textAlign: 'center',
},
});
export default class Spinner extends React.PureComponent {
static propTypes = {
animationStyle: ViewPropTypes.style,
animationType: oneOf(['none', 'slide', 'fade']),
autoPlay: bool,
autoSize: bool,
loop: bool,
message: string,
source: object,
speed: number,
style: ViewPropTypes.style,
supportedOrientations: arrayOf(string.isRequired),
textStyle: Text.propTypes.style,
visible: bool,
};
static defaultProps = {
animationStyle: {},
animationType: 'none',
autoPlay: true,
autoSize: true,
loop: true,
message: '',
source: require('./loading.json'), //eslint-disable-line
speed: 1,
style: {},
supportedOrientations: ['portrait'],
textStyle: {},
visible: false,
};
animation = React.createRef();
play = () => {
if (this.animation.current) {
this.animation.current.play();
}
};
reset = () => {
if (this.animation.current) {
this.animation.current.reset();
}
};
renderLoader = () => {
const {
animationStyle, autoPlay, autoSize, loop, source, speed,
} = this.props;
return (
<LottieAnimation
ref={this.animation}
autoPlay={autoPlay}
loop={loop}
style={[styles.animationStyle, animationStyle]}
source={source}
speed={speed}
autoSize={autoSize}
/>
);
};
renderText = () => {
const {
textStyle, message,
} = this.props;
return <Text style={[styles.textStyle, textStyle]}>{message}</Text>;
};
render() {
const {
animationType, style, visible, supportedOrientations,
} = this.props;
return (
<Modal
transparent
visible={visible}
animationType={animationType}
supportedOrientations={supportedOrientations}
onRequestClose={() => true}
>
<View style={[styles.container, style]}>
{this.renderLoader()}
{this.renderText()}
</View>
</Modal>
);
}
}