-
Notifications
You must be signed in to change notification settings - Fork 2
/
keyboardEvents.js
39 lines (35 loc) · 920 Bytes
/
keyboardEvents.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
import {
Keyboard,
Platform,
NativeAppEventEmitter,
} from 'react-native';
export const addKeyboardShowListener = (listener) => {
if (Platform.OS === 'android') {
return NativeAppEventEmitter.addListener('keyboardDidShow', (data) => {
listener(data);
})
} else {
Keyboard.addListener('keyboardDidShow', (data) => {
listener(data);
});
return 'keyboardDidShow';
}
};
export const addKeyboardHideListener = (listener) => {
if (Platform.OS === 'android') {
NativeAppEventEmitter.addListener('keyboardDidHide', (data) => {
listener(data);
});
} else {
Keyboard.addListener('keyboardDidHide', (data) => {
listener(data);
});
}
};
export const removeKeyboardListener = (subscription) => {
if (Platform.OS === 'android') {
NativeAppEventEmitter.removeSubscription(subscription);
} else {
Keyboard.removeListener(subscription);
}
};