Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ const keyboard = useKeyboard()

console.log('keyboard isKeyboardShow: ', keyboard.keyboardShown)
console.log('keyboard keyboardHeight: ', keyboard.keyboardHeight)
console.log('keyboard keyboardShowing: ', keyboard.keyboardShowing)
console.log('keyboard keyboardHiding: ', keyboard.keyboardHiding)

```

### `useInteractionManager`
Expand Down
8 changes: 8 additions & 0 deletions src/useKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@ const initialValue = {

export function useKeyboard() {
const [shown, setShown] = useState(false)
const [showing, setShowing] = useState(false)
const [hiding, setHiding] = useState(false)
const [coordinates, setCoordinates] = useState<{
start: ScreenRect
end: ScreenRect
}>(initialValue)
const [keyboardHeight, setKeyboardHeight] = useState<number>(0)

const handleKeyboardWillShow: KeyboardEventListener = (e) => {
setShowing(true)
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
}
const handleKeyboardDidShow: KeyboardEventListener = (e) => {
setShown(true)
setShowing(false)
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
setKeyboardHeight(e.endCoordinates.height)
}
const handleKeyboardWillHide: KeyboardEventListener = (e) => {
setHiding(true)
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
}
const handleKeyboardDidHide: KeyboardEventListener = (e) => {
setShown(false)
setHiding(false)
if (e) {
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
} else {
Expand All @@ -57,6 +63,8 @@ export function useKeyboard() {

return {
keyboardShown: shown,
keyboardShowing: showing,
keyboardHiding: hiding,
coordinates,
keyboardHeight,
}
Expand Down