Skip to content

Commit 6bdb1e6

Browse files
committed
keyboard deprecations
1 parent e455ebd commit 6bdb1e6

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

App/Mixins/KeyboardListener.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React from 'react';
2-
import KeyboardEvents from 'react-native-keyboardevents';
3-
var KeyboardEventEmitter = KeyboardEvents.Emitter;
2+
3+
import {
4+
Keyboard,
5+
} from 'react-native';
6+
47

58
var KeyboardListener = {
69
getInitialState: function() {
@@ -13,9 +16,13 @@ var KeyboardListener = {
1316
return this.state.keyboardSpace > 0;
1417
},
1518

16-
updateKeyboardSpace: function(frames) {
17-
if (this.isMounted() && frames && frames.end) {
18-
this.setState({keyboardSpace: frames.end.height});
19+
isKeyboardVisible: function() {
20+
return this.state.keyboardSpace > 0;
21+
},
22+
23+
updateKeyboardSpace: function(e) {
24+
if (this.isMounted() && e && e.endCoordinates) {
25+
this.setState({keyboardSpace: e.endCoordinates.height});
1926
}
2027
},
2128

@@ -25,15 +32,32 @@ var KeyboardListener = {
2532
}
2633
},
2734

35+
// onKeyboardHideCallback: function() {
36+
// // TODO handle case when the keyboard never showed up in the first place
37+
// // Might want to use state to check that it did showed up
38+
// if (this.params.onKeyboardHide) {
39+
// this.params.onKeyboardHide.call(this.originalComponent());
40+
// }
41+
// },
42+
43+
2844
componentDidMount: function() {
29-
KeyboardEventEmitter.on(KeyboardEvents.KeyboardDidShowEvent, this.updateKeyboardSpace);
30-
KeyboardEventEmitter.on(KeyboardEvents.KeyboardWillHideEvent, this.resetKeyboardSpace);
45+
this._keyboardSubscriptions = [];
46+
this._keyboardSubscriptions.push(Keyboard.addListener('keyboardWillShow', this.updateKeyboardSpace));
47+
this._keyboardSubscriptions.push(Keyboard.addListener('keyboardDidShow', this.updateKeyboardSpace));
48+
this._keyboardSubscriptions.push(Keyboard.addListener('keyboardWillHide', this.resetKeyboardSpace));
49+
this._keyboardSubscriptions.push(Keyboard.addListener('keyboardDidHide', this.resetKeyboardSpace));
50+
//if (this.params.onKeyboardHide) {
51+
// this._keyboardSubscriptions.push(Keyboard.addListener('keyboardDidHide', this.onKeyboardHideCallback));
52+
//}
3153
},
3254

3355
componentWillUnmount: function() {
34-
KeyboardEventEmitter.off(KeyboardEvents.KeyboardDidShowEvent, this.updateKeyboardSpace);
35-
KeyboardEventEmitter.off(KeyboardEvents.KeyboardWillHideEvent, this.resetKeyboardSpace);
56+
this._keyboardSubscriptions.forEach((subscription) => {
57+
subscription.remove();
58+
});
3659
},
60+
3761
};
3862

3963
export default KeyboardListener;

0 commit comments

Comments
 (0)