forked from heyman333/react-native-frame-loading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameLoading.js
62 lines (54 loc) · 1.35 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
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
}
componentDidUpdate() {
if (this.props.animating) {
const duration = this.props.duration
this._rotateView(duration)
}
}
_rotateView = duration => {
const views = this.props.views
const { viewOrder } = this.state
setTimeout(() => {
const viewOrder = this.increase++ % views.length
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,
view: PropTypes.array.isRequired,
loadingContainerStyle: PropTypes.object,
duration: PropTypes.number,
modalProps: PropTypes.object
}
FrameLoading.defaultProps = {
animating: false,
views: [],
loadingContainerStyle: {
justifyContent: "center",
alignItems: "center",
flex: 1
},
duration: 450,
modalProps: {}
}