-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.js
99 lines (88 loc) · 2.19 KB
/
Menu.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
import React, {Component} from 'react';
import {
Animated,
View,
Text,
StyleSheet,
TouchableOpacity,
TouchableWithoutFeedback,
Platform
} from 'react-native';
import {getNavbarHeight , getHeight ,getWidth } from './Navbar';
import MenuItem from './MenuItem';
export default class Menu extends Component {
constructor(props) {
super(props);
this.state = {
opacity: new Animated.Value(0),
shouldBlock: false
}
}
_animateOut = () => Animated.timing(this.state.opacity, {toValue: 0, duration: 200});
_animateIn = () => Animated.timing(this.state.opacity, {toValue: 1, duration: 200});
_itemSelected = (item) => () => {
this._animateOut().start(() => {
this.props.onItemSelected(item);
this.props.closeMenu();
});
};
componentDidMount = () => {
this._animateIn().start(() => this.setState({shouldBlock: true}));
};
_overlayClicked = () => {
this._animateOut().start(() => {
if (this.state.shouldBlock) {
this.props.closeMenu();
}
});
};
render() {
const {menuItems} = this.props;
return (
<TouchableWithoutFeedback
onPress={this._overlayClicked}>
{menuItems ? <View
style={styles.wrapper}>
<Animated.View style={[styles.menu, {opacity: this.state.opacity}]}>
{ menuItems
.map((item) => <MenuItem itemName = {item}
onItemSelected ={this.props.onItemSelected}
closeMenu={this.props.closeMenu}/>)}
</Animated.View>
</View> : <View/>}
</TouchableWithoutFeedback>
);
}
}
const menuStyle = {
position: 'absolute',
top: getNavbarHeight(),
right: 20,
width: 168,
backgroundColor: 'white'
};
if(Platform.OS === 'android') {
Object.assign(menuStyle, {
borderWidth: 1,
borderColor: '#e6e6e6'
});
} else {
Object.assign(menuStyle, {
shadowColor: 'black',
shadowRadius: 2,
shadowOpacity: .5,
shadowOffset: {
height: 2,
width: 0
}
})
}
const styles = StyleSheet.create({
wrapper: {
position: 'absolute',
top: 0,
height: getHeight(),
width: getWidth()
},
menu: menuStyle
});