File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -10,4 +10,5 @@ export {default as useScrollToItem} from './useScrollToItem';
10
10
export { default as useScrollTo } from './useScrollTo' ;
11
11
export { default as useThemeProps } from './useThemeProps' ;
12
12
export { default as useDebounce } from './useDebounce' ;
13
+ export { default as useKeyboardHeight } from './useKeyboardHeight' ;
13
14
export * from './useScrollTo' ;
Original file line number Diff line number Diff line change
1
+ import { useEffect , useState } from 'react' ;
2
+ import { Keyboard , KeyboardEvent } from 'react-native' ;
3
+
4
+ /**
5
+ * Hook that tracks keyboard height and provides real-time updates
6
+ */
7
+ const useKeyboardHeight = ( ) : number => {
8
+ const [ keyboardHeight , setKeyboardHeight ] = useState ( 0 ) ;
9
+
10
+ useEffect ( ( ) => {
11
+ const keyboardDidHideListener = Keyboard . addListener ( 'keyboardDidHide' , ( ) => {
12
+ setKeyboardHeight ( 0 ) ;
13
+ } ) ;
14
+
15
+ const keyboardDidShowListener = Keyboard . addListener ( 'keyboardDidShow' , ( e : KeyboardEvent ) => {
16
+ setKeyboardHeight ( e . endCoordinates . height ) ;
17
+ } ) ;
18
+
19
+ return ( ) => {
20
+ keyboardDidHideListener . remove ( ) ;
21
+ keyboardDidShowListener . remove ( ) ;
22
+ } ;
23
+ } , [ ] ) ;
24
+
25
+ return keyboardHeight ;
26
+ } ;
27
+
28
+ export default useKeyboardHeight ;
You can’t perform that action at this time.
0 commit comments