-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspinning-button.js
52 lines (46 loc) · 1.18 KB
/
spinning-button.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
import React, {Component} from 'react'
import * as t from 'prop-types'
import {Animated, TouchableOpacity} from 'react-native'
class SpinningButton extends Component {
constructor(props) {
super(props)
this.state = {
rotateValue: new Animated.Value(0),
active: true
}
}
_onPressButton = () => {
if (
this.state.rotateValue._value === 0 ||
this.state.rotateValue._value % 360 === 0
) {
Animated.spring(this.state.rotateValue, {
toValue: this.state.rotateValue._value + 360
}).start(() => this.props.onPress())
}
}
render() {
return (
<TouchableOpacity {...this.props} onPress={this._onPressButton}>
<Animated.View
style={{
transform: [
{
rotate: this.state.rotateValue.interpolate({
inputRange: [0, 360],
outputRange: ['0deg', '360deg']
})
}
]
}}>
{this.props.children}
</Animated.View>
</TouchableOpacity>
)
}
}
SpinningButton.propTypes = {
onPress: t.func.isRequired,
children: t.node.isRequired
}
export default SpinningButton