Skip to content

Commit 8b5f64e

Browse files
authored
Merge pull request #27 from eminsr/master
removeListener method has been deprecated
2 parents 190d773 + 180fa8d commit 8b5f64e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/Hooks/useKeyboard/index.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ const useKeyboard = (isEnable = true): [number] => {
1313
}
1414

1515
useEffect(() => {
16-
const keyboardShowEvent =
17-
Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow';
18-
const keyboardHideEvent =
19-
Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide';
2016
if (isEnable) {
21-
Keyboard.addListener(keyboardShowEvent, onKeyboardWillShow);
22-
Keyboard.addListener(keyboardHideEvent, onKeyboardWillHide);
17+
const keyboardShowEvent =
18+
Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow';
19+
const keyboardHideEvent =
20+
Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide';
21+
const showSubscription = Keyboard.addListener(keyboardShowEvent, onKeyboardWillShow);
22+
const hideSubscription = Keyboard.addListener(keyboardHideEvent, onKeyboardWillHide);
23+
return (): void => {
24+
showSubscription.remove();
25+
hideSubscription.remove();
26+
};
2327
}
24-
return (): void => {
25-
Keyboard.removeListener(keyboardShowEvent, onKeyboardWillShow);
26-
Keyboard.removeListener(keyboardHideEvent, onKeyboardWillHide);
27-
};
2828
}, [isEnable]);
2929

3030
return [keyboardHeight];

0 commit comments

Comments
 (0)