@@ -42,19 +42,28 @@ export function useKeyboard() {
42
42
}
43
43
44
44
useEffect ( ( ) => {
45
- Keyboard . addListener ( 'keyboardWillShow' , handleKeyboardWillShow )
46
- Keyboard . addListener ( 'keyboardDidShow' , handleKeyboardDidShow )
47
- Keyboard . addListener ( 'keyboardWillHide' , handleKeyboardWillHide )
48
- Keyboard . addListener ( 'keyboardDidHide' , handleKeyboardDidHide )
45
+ const subscriptions = [
46
+ Keyboard . addListener ( 'keyboardWillShow' , handleKeyboardWillShow ) ,
47
+ Keyboard . addListener ( 'keyboardDidShow' , handleKeyboardDidShow ) ,
48
+ Keyboard . addListener ( 'keyboardWillHide' , handleKeyboardWillHide ) ,
49
+ Keyboard . addListener ( 'keyboardDidHide' , handleKeyboardDidHide ) ,
50
+ ]
49
51
50
52
return ( ) => {
51
- Keyboard . removeListener ( 'keyboardWillShow' , handleKeyboardWillShow )
52
- Keyboard . removeListener ( 'keyboardDidShow' , handleKeyboardDidShow )
53
- Keyboard . removeListener ( 'keyboardWillHide' , handleKeyboardWillHide )
54
- Keyboard . removeListener ( 'keyboardDidHide' , handleKeyboardDidHide )
53
+ if ( Keyboard . removeListener ) {
54
+ // React Native < 0.65
55
+ Keyboard . removeListener ( 'keyboardWillShow' , handleKeyboardWillShow )
56
+ Keyboard . removeListener ( 'keyboardDidShow' , handleKeyboardDidShow )
57
+ Keyboard . removeListener ( 'keyboardWillHide' , handleKeyboardWillHide )
58
+ Keyboard . removeListener ( 'keyboardDidHide' , handleKeyboardDidHide )
59
+ } else {
60
+ // React Native >= 0.65
61
+ for ( const subscription of subscriptions ) {
62
+ subscription . remove ( )
63
+ }
64
+ }
55
65
}
56
66
} , [ ] )
57
-
58
67
return {
59
68
keyboardShown : shown ,
60
69
coordinates,
0 commit comments