UNPKG

@gechiui/components

Version:
35 lines (28 loc) 725 B
/** * External dependencies */ import { Keyboard, Dimensions } from 'react-native'; /** * GeChiUI dependencies */ import { useEffect, useState } from '@gechiui/element'; export default function useIsFloatingKeyboard() { const windowWidth = Dimensions.get( 'window' ).width; const [ floating, setFloating ] = useState( false ); useEffect( () => { const onKeyboardWillChangeFrame = ( event ) => { setFloating( event.endCoordinates.width !== windowWidth ); }; Keyboard.addListener( 'keyboardWillChangeFrame', onKeyboardWillChangeFrame ); return () => { Keyboard.removeListener( 'keyboardWillChangeFrame', onKeyboardWillChangeFrame ); }; }, [ windowWidth ] ); return floating; }