Skip to content

Commit 212c5c8

Browse files
committed
add initialValue in usekeyboard
1 parent 313960b commit 212c5c8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/useKeyboard.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import {useEffect, useState} from 'react'
22
import {Keyboard, KeyboardEventListener, ScreenRect} from 'react-native'
33

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+
49
export default function useKeyboard() {
510
const [shown, setShown] = useState(false)
611
const [coordinates, setCoordinates] = useState<{
712
start: ScreenRect
813
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)
1315
const [keyboardHeight, setKeyboardHeight] = useState<number>(0)
1416

1517
const handleKeyboardWillShow: KeyboardEventListener = e => {
@@ -28,10 +30,7 @@ export default function useKeyboard() {
2830
if (e) {
2931
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
3032
} 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)
3534
setKeyboardHeight(0)
3635
}
3736
}

0 commit comments

Comments
 (0)