KeyboardAvoidingScrollView
A component that adjusts vertical scroll position and bottom margin so the soft keyboard does not cover the active input.
<input><textarea>Installation
Also add the Text Field registry snippet used in the example below.
Props
Prop
Type
id?string | undefinedfocusable?boolean | undefinedbounces?boolean | undefinedenable-scroll?boolean | undefinedscroll-bar-enable?boolean | undefinedupper-threshold?number | undefinedlower-threshold?number | undefinedinitial-scroll-offset?number | undefinedinitial-scroll-to-index?number | undefinedbindlayoutchange?EventHandler<LayoutChangeDetailEvent<Target>> | undefinedbindscrolltoupper?((e: ScrollToUpperEvent) => void) | undefinedbindscrolltolower?((e: ScrollToLowerEvent) => void) | undefinedbindscroll?((e: ScrollEvent) => void) | undefinedbindscrollend?((e: ScrollEndEvent) => void) | undefinedbindcontentsizechanged?((e: ContentSizeChangedEvent) => void) | undefinedstyle?CSSProperties | undefinedchildren?ReactNodeclassName?string | undefinedbindtap?EventHandler<BaseTouchEvent<Target>> | undefinedbindtouchstart?EventHandler<BaseTouchEvent<Target>> | undefinedbindtouchend?EventHandler<BaseTouchEvent<Target>> | undefinedbindtouchcancel?EventHandler<BaseTouchEvent<Target>> | undefinedmain-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefinedUsage
Place it in the outermost area of a vertically scrolling input screen. keyboardGap is the gap between the keyboard and the active input area. scrollBehavior determines how to move to the avoidance position.
Place input elements inside TextField provided by the Text Field Input and Text Field Textarea registry snippets. It tracks the input area and bottom based on the Field boundary that this TextField creates internally. Input elements automatically pass focus and blur. Auto-height-adjusting TextField.Textarea also passes layout changes, so no separate registration props are needed.
On Android, if this component handles keyboard avoidance exclusively, specify android-set-soft-input-mode="nothing" on the input element. This prevents overlapping with separate pan or resize of the host window.
Examples
Single-line Input
When focus moves to TextField.Input at the bottom of the screen, it automatically scrolls to create a 24px gap between the input area and the keyboard.
This example uses native keyboard behavior. Run it with Lynx Explorer from the QR code tab and tap the address input area at the bottom of the screen to verify.
Auto-resizing Textarea
When multiple lines are entered in TextField.Textarea and the height changes, the position of the active input area is recalculated.
This example uses native input element auto-resize and keyboard avoidance behavior. Run it with Lynx Explorer from the QR code tab and enter multiple lines to verify.
Web Version Differences
- Uses Lynx keyboard global event and native node measurement instead of the browser's
visualViewportor CSS viewport units. - Adds only the necessary bottom spacer when the keyboard opens and pauses automatic movement during user scrolling.
- Browser form submission and automatic focus movement are not provided.
Unsupported Lynx Features
- Horizontal and nested scroll views are not supported.
- Keyboard toolbar height and caret-unit avoidance for large textareas are not yet implemented.