-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (75 loc) · 1.88 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
import * as React from 'react';
import {
View,
Platform,
Keyboard,
UIManager,
StyleSheet,
LayoutAnimation,
} from 'react-native';
export default class KeyboardSpacerView extends React.PureComponent {
static defaultProps = {
backgroundColor: '#f6f6f6',
extraSpace: 0,
};
constructor(props) {
super(props);
this.state = {
bottom: 0,
};
// Enable `LayoutAnimation` for Android.
if (UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
}
componentDidMount() {
const keyboardShowEvent =
Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow';
const keyboardHideEvent =
Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide';
this.keyboardShowListener = Keyboard.addListener(
keyboardShowEvent,
this.keyboardShow
);
this.keyboardHideListener = Keyboard.addListener(
keyboardHideEvent,
this.keyboardHide
);
}
componentWillUnmount() {
this.keyboardShowListener && this.keyboardShowListener.remove();
this.keyboardHideListener && this.keyboardHideListener.remove();
}
keyboardShow = e => {
LayoutAnimation.easeInEaseOut();
this.setState({
bottom: e.endCoordinates.height + this.props.extraSpace,
});
};
keyboardHide = e => {
LayoutAnimation.easeInEaseOut();
this.setState({
bottom: 0,
});
};
render() {
const { bottom } = this.state;
const { children, backgroundColor } = this.props;
if (!children) {
console.warn(`Missing children on KeyboardSpacerView component.`);
}
return (
<View style={[styles.container, { backgroundColor, bottom }]}>
{this.props.children}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
},
});