1
1
import { useEffect , useState } from 'react'
2
2
import { Keyboard , KeyboardEventListener , ScreenRect } from 'react-native'
3
3
4
+ const initialValue = {
5
+ start : { screenX : 0 , screenY : 0 , width : 0 , height : 0 } ,
6
+ end : { screenX : 0 , screenY : 0 , width : 0 , height : 0 }
7
+ }
8
+
4
9
export default function useKeyboard ( ) {
5
10
const [ shown , setShown ] = useState ( false )
6
11
const [ coordinates , setCoordinates ] = useState < {
7
12
start : ScreenRect
8
13
end : ScreenRect
9
- } > ( {
10
- start : { screenX : 0 , screenY : 0 , width : 0 , height : 0 } ,
11
- end : { screenX : 0 , screenY : 0 , width : 0 , height : 0 } ,
12
- } )
14
+ } > ( initialValue )
13
15
const [ keyboardHeight , setKeyboardHeight ] = useState < number > ( 0 )
14
16
15
17
const handleKeyboardWillShow : KeyboardEventListener = e => {
@@ -28,10 +30,7 @@ export default function useKeyboard() {
28
30
if ( e ) {
29
31
setCoordinates ( { start : e . startCoordinates , end : e . endCoordinates } )
30
32
} else {
31
- setCoordinates ( {
32
- start : { screenX : 0 , screenY : 0 , width : 0 , height : 0 } ,
33
- end : { screenX : 0 , screenY : 0 , width : 0 , height : 0 } ,
34
- } )
33
+ setCoordinates ( initialValue )
35
34
setKeyboardHeight ( 0 )
36
35
}
37
36
}
0 commit comments