11/* eslint-disable no-unused-vars */
2+ /* eslint-disable no-unused-expressions */
23import React , { useEffect , useState } from 'react' ;
34import { Keyboard } from 'react-native' ;
45
@@ -22,12 +23,22 @@ export default (config = {}) => {
2223 setVisible ( false ) ;
2324 }
2425
25- Keyboard . addListener ( showEvent , onKeyboardShow ) ;
26- Keyboard . addListener ( hideEvent , onKeyboardHide ) ;
26+ if ( Keyboard . removeListener ) {
27+ Keyboard . addListener ( showEvent , onKeyboardShow ) ;
28+ Keyboard . addListener ( hideEvent , onKeyboardHide ) ;
29+
30+ return ( ) => {
31+ Keyboard . removeListener ( showEvent , onKeyboardShow ) ;
32+ Keyboard . removeListener ( hideEvent , onKeyboardHide ) ;
33+ } ;
34+ }
35+
36+ const showSubscription = Keyboard . addListener ( showEvent , onKeyboardShow ) ;
37+ const hideSubscription = Keyboard . addListener ( hideEvent , onKeyboardHide ) ;
2738
2839 return ( ) => {
29- Keyboard . removeListener ( showEvent , onKeyboardShow ) ;
30- Keyboard . removeListener ( hideEvent , onKeyboardHide ) ;
40+ showSubscription ?. remove ( ) ;
41+ hideSubscription ?. remove ( ) ;
3142 } ;
3243 } , [ useWillShow , useWillHide ] ) ;
3344
0 commit comments