About this animation
A paste-friendly one-time-code field with animated slots and clear validation feedback.
How it works
- One transparent
TextInputreceives typing, autofill, and pasted codes. - Input is sanitized to digits and distributed across visual boxes.
- Shared values animate focus, digit entry, shake feedback, and the success cascade.
- Completion triggers a staggered pop, expanding accent ring, and clipped light sweep in under 600 ms.
- Controlled and uncontrolled modes share the same input path.
Install
npx expo install expo-linear-gradient react-native-reanimatedUsage
import OtpCodeInput from './OtpCodeInput';
<OtpCodeInput onComplete={(code) => verify(code)} />;
<OtpCodeInput length={4} accentColor="#16806A" boxSize={44} />;
<OtpCodeInput colorScheme="dark" success defaultValue="482197" />;Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Controlled code. |
defaultValue | string | '' | Initial uncontrolled code. |
length | number | 6 | Number of boxes. |
onChange | (code: string) => void | — | Receives each sanitized code. |
onComplete | (code: string) => void | — | Runs when all boxes are filled. |
error / success | boolean | false | Validation state. |
boxSize / gap | number | 48 / 8 | Slot dimensions. |
accentColor | string | '#6757E8' | Focus color. |
borderColor | string | '#D8D7DF' | Resting border color. |
errorColor / successColor | string | '#D9415D' / '#258A5B' | Feedback colors. |
backgroundColor / textColor | string | '#FFFFFF' / '#17151F' | Surface and digit colors. |
fontFamily | string | System font | Digit font. |
colorScheme | 'light' | 'dark' | 'auto' | 'auto' | Surface appearance, with system-aware dark mode. |
duration | number | 220 | Base animation duration. |
accessibilityLabel | string | 'One-time code' | Input label. |
style / inputStyle | style | — | Container and native-input styles. |
testID | string | — | Native-input test identifier. |
The ref exposes focus(), clear(), shake(), and succeed().
Compatibility
- Expo SDK 57, React Native 0.86, and Reanimated 4.5
- iOS, Android, and web supported; device verification pending
- 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.