suiss/uim · React Native Component

Keyboard Scroll View

A scroll view that keeps the focused text field visible above the on-screen keyboard.

Keyboard Scroll View is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Keyboard Scroll View on iOS in light mode

KeyboardScrollView wraps the React Native ScrollView. When the keyboard opens, it measures how much of the view the keyboard covers, adds matching space at the end of the content and scroll indicator, and scrolls just enough to bring the focused input above the keyboard.

Use it for forms and other screens with text fields that would otherwise end up behind the keyboard.

Installation

$ pnpm dlx @esuiss/uim@latest add keyboard-scroll-view

Manual

  1. Install the dependencies:
npx expo install cn
  1. Add the pieces it builds on: the primitives components/primitives/hooks.tsx, components/primitives/keyboard.tsx.

  2. Copy the source into components/ui/keyboard-scroll-view.tsx:

uniwind/components/ui/keyboard-scroll-view.tsx
import { cn } from "cn"
import * as React from "react"
import {
  Platform,
  ScrollView,
  type ScrollViewProps,
  TextInput,
  useWindowDimensions,
  View,
} from "react-native"
import { useComposedRefs } from "@/components/primitives/hooks"
import { useKeyboard } from "@/components/primitives/keyboard"

type KeyboardScrollViewContextValue = {
  scrollToFocused: () => void
}
  1. Update the import paths to match your project.

Usage

import { KeyboardScrollView } from "@/components/ui/keyboard-scroll-view"
<KeyboardScrollView className="-m-4" contentContainerClassName="gap-4 p-4">
  <Text variant="h3">Shipping address</Text>
  <Fields />
</KeyboardScrollView>

Place inputs anywhere inside the view; no extra setup is needed. Set bottomOffset to leave more space between the focused field and the keyboard.

All ScrollView props are passed through. By default taps on the content are handled while the keyboard is open (keyboardShouldPersistTaps="handled"), and dragging dismisses the keyboard.

KeyboardScrollViewContext exposes scrollToFocused, which children can call to bring the focused input into view again, for example after their layout changes.

Examples

Larger bottom offset

Keeps the focused field 64 points above the keyboard.

iOS
Keyboard Scroll View (larger bottom offset) on iOS in light mode

Focused

The last field is focused on mount and scrolled into view.

iOS
Keyboard Scroll View (focused) on iOS in light mode

With bottom bar

A form above a bottom bar with a full-width button.

iOS
Keyboard Scroll View (with bottom bar) on iOS in light mode

API Reference

KeyboardScrollView

ExtendsScrollViewPropsReact.RefAttributes<ScrollView>
PropType
About
Space kept between the focused input and the keyboard. Defaults to 16.
Type
number
Default
16

Accessibility

  • The view is a standard ScrollView, so screen reader scrolling works as usual.

Notes

  • keyboardDismissMode defaults to interactive on iOS and on-drag on Android.
  • After a touch while the keyboard is open, the view checks the focused input again after a short delay.
  • The view fills its parent with flex-1.
  • Only an input that is inside the visible frame of the scroll view is adjusted; inputs scrolled out of view are left alone.