digitalfabrik/integreat-app

View on GitHub
native/src/hooks/useKeyboardHeight.ts

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
import { useEffect, useState } from 'react'
import { Keyboard, KeyboardEvent } from 'react-native'

const useKeyboardHeight = (): number => {
  const [keyboardHeight, setKeyboardHeight] = useState(0)

  useEffect(() => {
    const onKeyboardWillShow = (e: KeyboardEvent) => {
      setKeyboardHeight(e.endCoordinates.height)
    }

    const subscription = Keyboard.addListener('keyboardWillShow', onKeyboardWillShow)

    return () => {
      subscription.remove()
    }
  }, [])

  return keyboardHeight
}

export default useKeyboardHeight