Skip to content

Commit 2966d50

Browse files
committed
add value to Coordinates when hide
1 parent e43398e commit 2966d50

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/useKeyboard.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
import {useEffect, useState} from 'react'
2-
import {Keyboard, KeyboardEventListener, ScreenRect} from 'react-native'
1+
import { useEffect, useState } from 'react'
2+
import { Keyboard, KeyboardEventListener, ScreenRect } from 'react-native'
33

44
export default function useKeyboard() {
55
const [shown, setShown] = useState(false)
66
const [coordinates, setCoordinates] = useState<{
77
start: ScreenRect
88
end: ScreenRect
99
}>({
10-
start: {screenX: 0, screenY: 0, width: 0, height: 0},
11-
end: {screenX: 0, screenY: 0, width: 0, height: 0},
10+
start: { screenX: 0, screenY: 0, width: 0, height: 0 },
11+
end: { screenX: 0, screenY: 0, width: 0, height: 0 },
1212
})
1313
const [keyboardHeight, setKeyboardHeight] = useState<number>(0)
1414

1515
const handleKeyboardWillShow: KeyboardEventListener = e => {
16-
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
16+
setCoordinates({ start: e.startCoordinates, end: e.endCoordinates })
1717
}
1818
const handleKeyboardDidShow: KeyboardEventListener = e => {
1919
setShown(true)
20-
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
20+
setCoordinates({ start: e.startCoordinates, end: e.endCoordinates })
2121
setKeyboardHeight(e.endCoordinates.height)
2222
}
2323
const handleKeyboardWillHide: KeyboardEventListener = e => {
24-
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
24+
setCoordinates({ start: e.startCoordinates, end: e.endCoordinates })
2525
}
2626
const handleKeyboardDidHide: KeyboardEventListener = e => {
2727
setShown(false)
2828
if (e) {
29-
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
29+
setCoordinates({ start: e.startCoordinates, end: e.endCoordinates })
30+
} else {
31+
setCoordinates({
32+
start: { screenX: 0, screenY: 0, width: 0, height: 0 }
33+
, end: { screenX: 0, screenY: 0, width: 0, height: 0 }
34+
})
3035
}
3136
setKeyboardHeight(0)
3237
}

0 commit comments

Comments
 (0)