Files
bsky-social-app/src/lib/hooks/useIsKeyboardVisible.ts
T
Eric Bailey 0589bd7d9e Move /platform/detection vars into /env (#9707)
* Add platform vars to env

* Replace /platform/detection with /env
2026-01-16 16:28:17 -06:00

37 lines
925 B
TypeScript

import {useEffect, useState} from 'react'
import {Keyboard} from 'react-native'
import {IS_IOS} from '#/env'
export function useIsKeyboardVisible({
iosUseWillEvents,
}: {
iosUseWillEvents?: boolean
} = {}) {
const [isKeyboardVisible, setKeyboardVisible] = useState(false)
// NOTE
// only iOS supports the "will" events
// -prf
const showEvent =
IS_IOS && iosUseWillEvents ? 'keyboardWillShow' : 'keyboardDidShow'
const hideEvent =
IS_IOS && iosUseWillEvents ? 'keyboardWillHide' : 'keyboardDidHide'
useEffect(() => {
const keyboardShowListener = Keyboard.addListener(showEvent, () =>
setKeyboardVisible(true),
)
const keyboardHideListener = Keyboard.addListener(hideEvent, () =>
setKeyboardVisible(false),
)
return () => {
keyboardHideListener.remove()
keyboardShowListener.remove()
}
}, [showEvent, hideEvent])
return [isKeyboardVisible]
}