-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFrameLoading.js
59 lines (51 loc) · 1.33 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
import React from "react"
import { View, Modal, StyleSheet, Image, Text } 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(prevProps, prevState, snapshot) {
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 { modalContainerStyle } = this.props
return (
<Modal {...this.props.modalProps} visible={this.props.animating}>
<View style={modalContainerStyle}>{view}</View>
</Modal>
)
}
}
FrameLoading.proptypes = {
animating: PropTypes.bool.isRequired,
view: PropTypes.array.isRequired,
modalContainerStyle: PropTypes.object,
duration: PropTypes.number
}
FrameLoading.defaultProps = {
modalContainerStyle: {
justifyContent: "center",
alignItems: "center",
flex: 1
},
duration: 450,
views: []
}