Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add value to Coordinates when hide #120

Merged
Merged
15 changes: 10 additions & 5 deletions src/useKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {useEffect, useState} from 'react'
import {Keyboard, KeyboardEventListener, ScreenRect} from 'react-native'

const emptyCoordinates = Object.freeze({screenX:0,screenY:0,width:0,height:0})
pvinis marked this conversation as resolved.
Show resolved Hide resolved
pvinis marked this conversation as resolved.
Show resolved Hide resolved
const initialValue = {
start: emptyCoordinates,
end: emptyCoordinates,
}

export function useKeyboard() {
const [shown, setShown] = useState(false)
const [coordinates, setCoordinates] = useState<{
start: ScreenRect
end: ScreenRect
}>({
start: {screenX: 0, screenY: 0, width: 0, height: 0},
end: {screenX: 0, screenY: 0, width: 0, height: 0},
})
}>(initialValue)
const [keyboardHeight, setKeyboardHeight] = useState<number>(0)

const handleKeyboardWillShow: KeyboardEventListener = (e) => {
Expand All @@ -27,8 +30,10 @@ export function useKeyboard() {
setShown(false)
if (e) {
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
} else {
setCoordinates(initialValue)
setKeyboardHeight(0)
}
setKeyboardHeight(0)
}

useEffect(() => {
Expand Down