Skip to content
Native Animation
Base Input OTP animation previewBase Input OTP animation preview

This preview uses fictional demo content. See the props below for the customization options available in this component.

npx nativeanimation add base-input-otp

Base Input OTP

React Native OTP Input Component

A passcode field with a sliding focus ring and configurable code length, digit groups, and theme.

Native Animation Base · Free · MIT

Add to your project

Copy the component and its assets into your app with the Native Animation CLI, or paste the agent prompt into Claude Code, Codex or Cursor once the MCP server is connected.

About this component

A passcode field with a sliding focus ring and configurable code length, digit groups, and theme.

How it works

  1. One invisible numeric TextInput owns focus, autofill, and the keyboard.
  2. Visible slots render the current string so the layout stays predictable on every platform.
  3. A shared focus ring springs between slots while new digits use a glyph spring.
  4. Pasted codes are accepted as one change, and completion is reported through onComplete.
  5. Error feedback uses a short horizontal shake and destructive border color.

Install

npx nativeanimation add base-input-otp
npx expo install react-native-gesture-handler react-native-reanimated react-native-worklets

Usage

<BaseInputOTP value={code} onChangeText={setCode} onComplete={submit} />
<BaseInputOTP length={6} groups={[3, 3]} error={hasError} autoFocus accessibilityLabel="Verification code" />

Props

PropTypeDefaultDescription
lengthnumber6Number of numeric characters.
valuestring""Controlled code value.
onChangeText(value: string) => void—Called with filtered numeric text.
onComplete(code: string) => void—Called when the code reaches length.
groupsnumber[][length]Slot groups separated by an en dash.
errorbooleanfalseUses destructive styling and shakes the field.
disabledbooleanfalseDisables focus and input.
autoFocusbooleanfalseFocuses the hidden input on mount.
themeBaseThemeproviderOverrides the family theme.
styleStyleProp<ViewStyle>—Root style.
testIDstring—Stable root identifier.

Compatibility

Expo SDK 58 · React Native 0.88 · Reanimated 4.7 · react-native-worklets 0.13. Runs on iOS, Android, and web in Expo Go or a development build.

Accessibility

The hidden input exposes one-time-code autofill and a numeric keyboard. The root announces the field label and disabled state. Reduced motion removes slot and error movement while preserving focus and color feedback.

Source code

Loading public source…