One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

Keyboard

Keyboard tracking, avoidance, and control, built in from react-native-keyboard-controller

one/keyboard follows the software keyboard frame by frame on the UI thread, moves content out of its way, and lets you dismiss it, move focus between fields, and drag it closed. It is react-native-keyboard-controller by Kiryl Ziusko, built into One, so an app gets it without another native dependency. The API matches the library’s, so the library’s documentation applies to every component and hook here.

iOS and Android run the native implementation. On web the components render plain views and the module calls do nothing.

Usage

Wrap the app once, near the root:

import { KeyboardProvider } from 'one/keyboard'
export default function Layout({ children }) {
return <KeyboardProvider>{children}</KeyboardProvider>
}

Then read the keyboard where you need it:

import Animated, { useAnimatedStyle } from 'react-native-reanimated'
import { KeyboardController, useReanimatedKeyboardAnimation } from 'one/keyboard'
function Composer() {
const { height } = useReanimatedKeyboardAnimation()
const style = useAnimatedStyle(() => ({
transform: [{ translateY: height.value }],
}))
return (
<Animated.View style={style}>
<Send onPress={() => KeyboardController.dismiss()} />
</Animated.View>
)
}

height is negative while the keyboard is open and follows the keyboard’s own animation curve, including while a finger drags it.

What it includes

Moving from react-native-keyboard-controller

Change the import from react-native-keyboard-controller to one/keyboard and remove the package. Both can be installed side by side while you move over: One’s native classes, components, and selectors use their own names.

Four things behave differently:

Edit this page on GitHub.