-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLoadingSpinner.js
executable file
·104 lines (95 loc) · 2.84 KB
/
LoadingSpinner.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
/**
* The examples provided by Oculus are for non-commercial testing and
* evaluation purposes only.
*
* Oculus reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* OCULUS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
'use strict';
import React from 'react';
import {Animated, asset, Image, View} from 'react-360';
// Import from React Native.
const Easing = require('Easing');
/**
* Displays a spinning loading indicator. Fades in after a configurable delay,
* which looks nice and prevents spinner from appearing when loading is quick.
*
* When using with CylinderLayer, set pixelsPerMeter to convert units, otherise
* set translateZ to specify distance between camera and spinner.
*/
class LoadingSpinner extends React.Component {
static defaultProps = {
delay: 500,
height: 0.5,
pixelsPerMeter: 1,
rotateY: 0,
source: asset('circle_ramp.png'),
speed: 1500,
translateX: 0,
translateZ: 0,
width: 0.5,
};
constructor(props) {
super();
this.state = {
rotationAnim: new Animated.Value(0),
opacityAnim: new Animated.Value(0),
};
}
_rotationAnimate() {
this.state.rotationAnim.setValue(0);
Animated.timing(this.state.rotationAnim, {
duration: this.props.speed,
easing: Easing.linear,
toValue: -360,
}).start(status => {
status.finished && this._rotationAnimate();
});
}
componentDidMount() {
Animated.timing(this.state.opacityAnim, {
delay: this.props.delay,
duration: this.props.speed,
easing: Easing.linear,
toValue: 1,
}).start();
this._rotationAnimate();
}
render() {
const PPM = this.props.pixelsPerMeter;
return (
<Animated.View
style={[
this.props.style,
{
opacity: this.state.opacityAnim,
position: 'absolute',
transform: [
// Use rotateY and translateZ for 3D, or translateX if using pixels.
{rotateY: this.props.rotateY},
{translateZ: this.props.translateZ},
{translateX: this.props.translateX},
// Spin! Must be the last transform applied.
{rotateZ: this.state.rotationAnim},
],
},
]}>
<Image
style={{
height: this.props.height * PPM,
width: this.props.width * PPM,
}}
source={this.props.source}
/>
</Animated.View>
);
}
}
module.exports = LoadingSpinner;