This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RotateWheel.js
121 lines (107 loc) · 2.88 KB
/
RotateWheel.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
import React, {Component} from 'react';
import {Animated, Easing, Image, StyleSheet, TouchableOpacity, View} from "react-native"
import {deviceWidth} from "./styleHelper"
class RotateWheel extends Component {
constructor(props) {
super(props);
this.state = {
prizeSections: 8,
rotating: false,
destination: -1,
};
this.rotateDeg = new Animated.Value(0)
this.rotateDeg.addListener(this.rotateListener)
}
rotateListener = (value) => {
console.log('rotateDeg changing', value)
}
rotateImgDelegate = () => {
if (!this.state.rotating) {
this.rotateDeg = new Animated.Value(0)
this.setState({
rotating: !this.state.rotating,
}, () => {
this.rotateImg();
});
} else {
this.rotateToIndex(7)
}
};
rotateImg = () => {
Animated.timing(this.rotateDeg, {
toValue: 1000,
duration: 15000,
easing: Easing.linear,
useNativeDriver: true
}).start(() => {
console.log('end callback')
})
};
rotateToIndex = (destination) => {
let oneTimeRotate = (destination * 100 / 8) + 6.25;
console.log("oneTimeRotate", {oneTimeRotate})
this.rotateDeg.stopAnimation((rotateValue) => {
console.log("oneTimeRotate", {rotateValue})
let rotateAll = Math.ceil(rotateValue / 100) * 100 + oneTimeRotate
let rotateTime = 20 * (rotateAll - rotateValue)
console.log("oneTimeRotate", {rotateAll})
Animated.timing(this.rotateDeg, {
toValue: rotateAll,
duration: rotateTime,
easing: Easing.out(Easing.ease),
}).start(() => {
this.setState({
rotating: false,
destination: -1,
})
})
})
}
render() {
return (
<View style={styles.container}>
<Animated.View style={{
transform: [
{
rotate: this.rotateDeg.interpolate({
inputRange: [0, 100],
outputRange: ['0deg', '360deg']
})
}]
}}>
<Image
source={require('./Images/rotateWheel.png')}
style={[styles.mainImg,]}>
</Image>
</Animated.View>
<TouchableOpacity onPress={this.rotateImgDelegate} style={styles.centerPoint}>
<Image source={require('./Images/rotatePointer.png')} style={styles.imgPoint}/>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
imgPoint: {
width: 93,
height: 104,
},
centerPoint: {
position: 'absolute',
left: (deviceWidth-60-93)/2,
top: (deviceWidth-60-115)/2,
},
mainImg: {
width: deviceWidth-60,
height: deviceWidth-60,
alignItems: 'center',
justifyContent: 'center',
resizeMode: 'contain',
position: 'relative'
}
});
RotateWheel.propTypes = {};
export default RotateWheel;