Skip to content

Commit 13355e0

Browse files
committed
[fix][useKeyboard] Adapt unsubscription for new EventEmitter API
1 parent c62cf6f commit 13355e0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/useKeyboard.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ export function useKeyboard() {
5050
]
5151

5252
return () => {
53-
if (Keyboard.removeListener) {
53+
if (typeof subscriptions?.[0]?.remove === 'function') {
54+
// React Native >= 0.65
55+
for (const subscription of subscriptions) {
56+
subscription.remove()
57+
}
58+
} else {
5459
// React Native < 0.65
5560
Keyboard.removeListener('keyboardWillShow', handleKeyboardWillShow)
5661
Keyboard.removeListener('keyboardDidShow', handleKeyboardDidShow)
5762
Keyboard.removeListener('keyboardWillHide', handleKeyboardWillHide)
5863
Keyboard.removeListener('keyboardDidHide', handleKeyboardDidHide)
59-
} else {
60-
// React Native >= 0.65
61-
for (const subscription of subscriptions) {
62-
subscription.remove()
63-
}
6464
}
6565
}
6666
}, [])

0 commit comments

Comments
 (0)