useKeyboardInset
Keep bottom-aligned content above the software keyboard.
To detect how much of a NitroUI screen's safe area the visible keyboard frame covers, use the useKeyboardInset hook. It returns the overlap in points for a docked software keyboard. The value comes from the nearest view controller and updates as the keyboard moves on iOS and Android. It is 0 when the screen's safe area is clear of the docked keyboard.
Keep a text field above the keyboard
Add the keyboard inset to useSafeAreaInsets().bottom. This screen keeps the text field above the bottom safe area when the keyboard is hidden and moves it up as the keyboard appears. Safe areas
import { TextInput, View, useKeyboardInset, useSafeAreaInsets } from 'nitro-ui-renderer'
export function MessageComposer() {
const safeArea = useSafeAreaInsets()
const keyboardInset = useKeyboardInset()
return (
<View
layout={{
flex: 1,
justifyContent: 'flex-end',
paddingLeft: safeArea.left + 16,
paddingRight: safeArea.right + 16,
paddingBottom: safeArea.bottom + keyboardInset + 12,
}}
>
<TextInput placeholder="Message" />
</View>
)
}