Skip to content
Native Animation
OTP Code Input animation preview

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

npx nativeanimation add otp-code-input
Micro

OTP Code Input

React Native OTP Input with Animated Slots

A passcode field with animated slots and validation feedback, with configurable code length, slot size, accent color, and font.

$9 for this animation

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 animation

React Native OTP input screens need to accept typing, pasted codes, and platform autofill without turning each visible slot into a separate field. This component keeps one native TextInput as the source of truth, sanitizes its value to digits, and distributes the result across animated slots. Use it for sign-in verification, account recovery, payment approval, or any short one-time code flow. Reanimated drives focus, digit entry, validation shake, and the success cascade on the UI thread, while Expo Linear Gradient creates the clipped completion sweep. It supports controlled and uncontrolled values, configurable code length and slot geometry, imperative focus and feedback methods, and a single concise screen-reader target.

When to use it

  • Verify a phone number or email address.
  • Confirm a sensitive account action.
  • Accept a pasted or autofilled one-time code.
  • Show animated error and success feedback.

Related guides

A passcode field with animated slots and validation feedback, with configurable code length, slot size, accent color, and font.

How it works

  1. One transparent TextInput receives typing, autofill, and pasted codes.
  2. Input is sanitized to digits and distributed across visual boxes.
  3. Shared values animate focus, digit entry, shake feedback, and the success cascade.
  4. Completion triggers a staggered pop, expanding accent ring, and clipped light sweep in under 600 ms.
  5. Controlled and uncontrolled modes share the same input path.

Install

npx expo install expo-linear-gradient react-native-reanimated react-native-worklets

Usage

import OtpCodeInput from './OtpCodeInput';

<OtpCodeInput onComplete={(code) => verify(code)} />;
<OtpCodeInput length={4} accentColor="#16806A" boxSize={44} />;
<OtpCodeInput colorScheme="dark" success defaultValue="482197" />;

Props

PropTypeDefaultDescription
valuestring—Controlled code.
defaultValuestring''Initial uncontrolled code.
lengthnumber6Number of boxes.
onChange(code: string) => void—Receives each sanitized code.
onComplete(code: string) => void—Runs when all boxes are filled.
error / successbooleanfalseValidation state.
boxSize / gapnumber48 / 8Slot dimensions.
accentColorstring'#6757E8'Focus color.
borderColorstring'#D8D7DF'Resting border color.
errorColor / successColorstring'#D9415D' / '#258A5B'Feedback colors.
backgroundColor / textColorstring'#FFFFFF' / '#17151F'Surface and digit colors.
fontFamilystringSystem fontDigit font.
colorScheme'light' | 'dark' | 'auto''auto'Surface appearance, with system-aware dark mode.
durationnumber220Base animation duration.
accessibilityLabelstring'One-time code'Input label.
style / inputStylestyle—Container and native-input styles.
testIDstring—Native-input test identifier.

The ref exposes focus(), clear(), shake(), and succeed().

Compatibility

  • Expo SDK 58, React Native 0.88, and Reanimated 4.7
  • iOS, Android, and web supported.
  • Works in Expo Go

Accessibility

The native field exposes one concise screen-reader target and supports platform OTP autofill. Reduced Motion removes travel, bounce, blinking, and stagger delays while preserving every state change.

FAQ

Does this React Native OTP input work in Expo Go?
Yes. It uses Expo Linear Gradient and Reanimated versions included with Expo SDK 58 and Expo SDK 57, so its README does not require a custom development build. Each published piece is reviewed on physical iPhone and Android devices with Expo Go before release.
Can I change the code length and slot appearance?
Yes. Configure length, boxSize, gap, colors, fontFamily, timing, and light or dark appearance. The component also supports controlled and uncontrolled values.
How does it handle accessibility and Reduce Motion?
Assistive technology sees one labeled native input instead of six noisy fields. Reduce Motion removes travel, bounce, blinking, and staggered delays while preserving every input and validation state.