Skip to content

Commit 9f95f5d

Browse files
author
alvaromb
committed
closes #7 Solved a remove listener bug that caused all listeners to be removed instead of the current scroll view
1 parent 955392d commit 9f95f5d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/KeyboardAwareMixin.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const KeyboardAwareMixin = {
1313

1414
getInitialState: function (props) {
1515
this.viewIsInsideTabBar = false
16+
this.keyboardWillShowEvent = undefined
17+
this.keyboardWillHideEvent = undefined
1618
return {
1719
keyboardSpace: 0,
1820
}
@@ -35,14 +37,13 @@ const KeyboardAwareMixin = {
3537

3638
componentDidMount: function () {
3739
// Keyboard events
38-
DeviceEventEmitter.addListener('keyboardWillShow', this.updateKeyboardSpace)
39-
DeviceEventEmitter.addListener('keyboardWillHide', this.resetKeyboardSpace)
40+
this.keyboardWillShowEvent = DeviceEventEmitter.addListener('keyboardWillShow', this.updateKeyboardSpace)
41+
this.keyboardWillHideEvent = DeviceEventEmitter.addListener('keyboardWillHide', this.resetKeyboardSpace)
4042
},
4143

4244
componentWillUnmount: function () {
43-
// TODO: figure out if removeAllListeners is the right thing to do
44-
DeviceEventEmitter.removeAllListeners('keyboardWillShow')
45-
DeviceEventEmitter.removeAllListeners('keyboardWillHide')
45+
this.keyboardWillShowEvent.remove()
46+
this.keyboardWillHideEvent.remove()
4647
},
4748

4849
/**

0 commit comments

Comments
 (0)