-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
110 lines (94 loc) · 2.21 KB
/
index.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
import React, {Component, PropTypes} from 'react';
import {
View,
ScrollView,
StyleSheet,
Easing,
Animated,
Dimensions
} from 'react-native';
const screen = Dimensions.get("window");
const MENU_WIDTH = screen.width * 0.5;
const MENU_HEIGHT = screen.height;
class BubbleMenu extends Component{
constructor(props){
super(props);
const { show } = props;
const openMenuValue = show ? screen.width - 25 : 50;
const opacityValue = show ? 1 : 0;
this.state = {
openMenu : new Animated.Value(openMenuValue),
opacity : new Animated.Value(opacityValue)
}
}
componentWillReceiveProps(nextState){
const {show} = nextState;
let toValue = show ? screen.width - 25 : 50;
Animated.parallel([
Animated[show ? "spring" : "timing"](
this.state.openMenu,{
toValue,
delay : show ? 0 : 195,
duration : 225,
easing : Easing.inOut(Easing.ease)
}
),
Animated.timing(
this.state.opacity,{
toValue : show ? 1 : 0,
delay : show ? 195 : 0,
duration : 195,
easing : Easing.inOut(Easing.ease)
}
)
]).start();
}
render(){
const {show, items, openBtn, color, style} = this.props;
return(
<Animated.View style={[styles.container,{
width : this.state.openMenu,
backgroundColor : show ? (color) ? color : "#ffffff" : (color) ? color : "#fafafa"
},style]}>
<View
style={styles.button}
pointerEvents={show ? "none" : "auto" }>
{openBtn}
</View>
<Animated.View style={[styles.items,{
opacity : this.state.opacity
}]} pointerEvents={show ? "auto" : "none" }>
{items}
</Animated.View>
</Animated.View>
)
}
}
BubbleMenu.propTypes = {
color : PropTypes.string,
show : PropTypes.bool.isRequired,
items : PropTypes.array.isRequired,
openBtn : PropTypes.object.isRequired,
style : PropTypes.number
}
const styles = StyleSheet.create({
container : {
justifyContent: 'center',
alignItems: 'center',
borderRadius : 50 / 2
},
button : {
width : 50,
height : 50,
borderRadius : 50 / 2,
justifyContent: 'center',
alignItems: 'center'
},
items : {
flexDirection : "row",
alignItems : "center",
justifyContent : "space-between",
marginTop : -50
}
});
export default BubbleMenu;