-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFrameLoading.js
71 lines (61 loc) · 1.54 KB
/
FrameLoading.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
import React from 'react';
import { View, Modal } from 'react-native';
import PropTypes from 'prop-types';
export default class FrameLoading extends React.Component {
constructor(props) {
super(props);
this.state = {
viewOrder: 0,
};
this.increase = 1;
}
componentDidMount() {
const { viewOrder } = this.state;
this._mounted = true;
this.setState({ viewOrder });
}
componentDidUpdate() {
if (this.props.animating) {
const { duration } = this.props;
this._rotateView(duration);
}
}
componentWillUnmount() {
this._mounted = false;
}
_rotateView = duration => {
const { views } = this.props;
setTimeout(() => {
const viewOrder = this.increase++ % views.length;
if (this._mounted) {
this.setState({ viewOrder });
}
}, duration);
};
render() {
const { viewOrder } = this.state;
const view = this.props.views[viewOrder];
const { loadingContainerStyle } = this.props;
return (
<Modal {...this.props.modalProps} visible={this.props.animating}>
<View style={loadingContainerStyle}>{view}</View>
</Modal>
);
}
}
FrameLoading.propTypes = {
animating: PropTypes.bool.isRequired,
views: PropTypes.arrayOf(PropTypes.element).isRequired,
loadingContainerStyle: PropTypes.shape({}),
duration: PropTypes.number,
modalProps: PropTypes.shape({}),
};
FrameLoading.defaultProps = {
loadingContainerStyle: {
justifyContent: 'center',
alignItems: 'center',
flex: 1,
},
duration: 450,
modalProps: {},
};