-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCircleTransition.js
104 lines (95 loc) · 3.49 KB
/
CircleTransition.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
import React, { Component } from 'react'
import { View, Animated, Dimensions } from 'react-native'
import * as Animatable from 'react-native-animatable'
const {width} = Dimensions.get('window')
class CircleTransition extends Component {
scale = new Animated.Value(0.00001)
constructor (props) {
super(props)
this.state = {
show: false,
showChildren: true,
animating: false
}
this.collapse = this.collapse.bind(this)
this.expand = this.expand.bind(this)
this.toggle = this.toggle.bind(this)
}
render () {
const {backgroundColor, style, revealPositionArray} = this.props
return (
this.state.show
? <View
style={{ ...style, overflow: 'hidden' }}
>
<Animated.View style={{
position: 'absolute',
backgroundColor: backgroundColor,
bottom: revealPositionArray.bottom === true ? -width / 2 : undefined,
left: revealPositionArray.left === true ? -width / 2 : undefined ,
top: revealPositionArray.top === true ? -width / 2 : undefined,
right: revealPositionArray.right === true ? -width / 2 : undefined,
width: width,
height: width,
borderRadius: width / 2,
transform: [{
scale: this.scale
}]
}} />
{this.state.showChildren &&
<Animatable.View ref={(ref) => { this.childContainer = ref }} style={{opacity: 0, flex: 1}}>
{this.props.children}
</Animatable.View>
}
</View>
: null
)
}
expand () {
const {duration} = this.props
if (this.state.animating === false) {
this.setState({show: true, animating: true}, () => {
Animated.timing(
this.scale,
{
useNativeDriver: true,
fromValue: 0,
toValue: 5,
duration: duration
}
).start((e) => {
if (e.finished === true) {
if (this.childContainer!==null && this.childContainer !== undefined) {
this.childContainer.fadeIn(200).then(() => this.setState({animating: false}))
}
}
})
})
}
}
collapse () {
const {duration} = this.props
if (this.state.animating === false) {
this.setState({animating: true})
if (this.childContainer!==null && this.childContainer !== undefined) {
this.childContainer.fadeOut(200)
}
Animated.timing(
this.scale,
{
useNativeDriver: true,
toValue: 0,
duration: duration
}
).start((e) => {
if (e.finished === true) {
this.setState({show: false, animating: false})
}
})
}
}
toggle () {
this.state.show === false ? this.expand() : this.collapse()
}
}
export default CircleTransition