Skip to content

Commit 378afac

Browse files
authored
Merge pull request #120 from Gamal-Shaban/fix-keyboard-android-2
add value to Coordinates when hide
2 parents 5c06a21 + 3b369b8 commit 378afac

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/useKeyboard.ts

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

4+
const emptyCoordinates = Object.freeze({
5+
screenX: 0,
6+
screenY: 0,
7+
width: 0,
8+
height: 0,
9+
})
10+
const initialValue = {
11+
start: emptyCoordinates,
12+
end: emptyCoordinates,
13+
}
14+
415
export function useKeyboard() {
516
const [shown, setShown] = useState(false)
617
const [coordinates, setCoordinates] = useState<{
718
start: ScreenRect
819
end: ScreenRect
9-
}>({
10-
start: {screenX: 0, screenY: 0, width: 0, height: 0},
11-
end: {screenX: 0, screenY: 0, width: 0, height: 0},
12-
})
20+
}>(initialValue)
1321
const [keyboardHeight, setKeyboardHeight] = useState<number>(0)
1422

1523
const handleKeyboardWillShow: KeyboardEventListener = (e) => {
@@ -27,8 +35,10 @@ export function useKeyboard() {
2735
setShown(false)
2836
if (e) {
2937
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
38+
} else {
39+
setCoordinates(initialValue)
40+
setKeyboardHeight(0)
3041
}
31-
setKeyboardHeight(0)
3242
}
3343

3444
useEffect(() => {

0 commit comments

Comments
 (0)