-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.js
127 lines (112 loc) · 2.67 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React, { PureComponent } from "react";
import {
Animated,
StyleSheet,
View,
TouchableWithoutFeedback,
Keyboard,
TextInput
} from "react-native";
import emitter from "tiny-emitter/instance";
import { HEIGHT } from "./Constants";
import { ANDROID } from "./Constants";
import CityPicker from "./CalendarCityPicker";
export default class Menu extends PureComponent {
state = {
visible: false,
opacity: new Animated.Value(0)
};
componentDidMount() {
emitter.on("toggle-menu", this._toggleMenu);
emitter.on("toggle-search", this._toggleSearch);
emitter.on("info-pop", this._onInfoPop);
if (ANDROID) {
this.keyboardWillHideListener = Keyboard.addListener(
"keyboardDidHide",
this._keyboardWillHide
);
}
}
_keyboardWillHide = () => {
if (ANDROID) {
TextInput.State.blurTextInput(TextInput.State.currentlyFocusedField());
this._dismiss();
}
};
componentWillUnmount() {
emitter.off("toggle-search", this._toggleSearch);
emitter.off("info-pop", this._onInfoPop);
if (ANDROID) {
this.keyboardWillHideListener.remove();
}
}
componentDidUpdate(prev) {
if (prev.visible !== this.state.visible) {
const toValue = this.state.visible ? 1 : 0;
Animated.timing(
this.state.opacity,
{ toValue, duration: 250 },
{ useNativeDriver: true }
).start();
}
}
_toggleMenu = visible => {
this.setState({
visible
});
};
_toggleSearch = visible => {
this.setState({
visible
});
if (visible) {
this._search.getWrappedInstance().focus();
}
};
_dismiss = () => {
this.setState({
visible: false
});
};
_setSearchRef = ref => {
this._search = ref;
};
_onInfoPop = () => {
if (this.state.visible) {
this._search.getWrappedInstance().focus();
}
};
render() {
const opacity = this.state.opacity.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
extrapolate: "clamp"
});
const containerStyle = [
styles.container,
{
opacity
}
];
const pointerEvents = this.state.visible ? "auto" : "none";
return (
<Animated.View style={containerStyle} pointerEvents={pointerEvents}>
<TouchableWithoutFeedback onPress={this._dismiss}>
<View style={styles.bg} />
</TouchableWithoutFeedback>
<CityPicker />
</Animated.View>
);
}
}
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
justifyContent: "flex-end",
elevation: 6
},
bg: {
...StyleSheet.absoluteFillObject,
backgroundColor: "rgba(0,0,0,0.96)"
}
});