diff --git a/src/OtpInput/OtpInput.tsx b/src/OtpInput/OtpInput.tsx index 2495af3..a139689 100644 --- a/src/OtpInput/OtpInput.tsx +++ b/src/OtpInput/OtpInput.tsx @@ -1,5 +1,5 @@ -import { forwardRef, useImperativeHandle } from "react"; -import { Platform, Pressable, Text, TextInput, View } from "react-native"; +import { forwardRef, useImperativeHandle, useMemo } from "react"; +import { Animated, Platform, Pressable, Text, TextInput, View } from "react-native"; import { styles } from "./OtpInput.styles"; import { OtpInputProps, OtpInputRef } from "./OtpInput.types"; import { VerticalStick } from "./VerticalStick"; @@ -22,6 +22,7 @@ export const OtpInput = forwardRef((props, ref) => { theme = {}, textInputProps, type = "numeric", + useAnimatedComponents = false, } = props; const { containerStyle, @@ -57,8 +58,19 @@ export const OtpInput = forwardRef((props, ref) => { return stylesArray; }; + const { ViewComponent, PressableComponent, TextComponent } = useMemo(() => { + if (useAnimatedComponents) { + return { + ViewComponent: Animated.View, + PressableComponent: Animated.createAnimatedComponent(Pressable), + TextComponent: Animated.Text, + }; + } + return { ViewComponent: View, PressableComponent: Pressable, TextComponent: Text }; + }, [useAnimatedComponents]); + return ( - + {Array(numberOfDigits) .fill(0) .map((_, index) => { @@ -68,7 +80,7 @@ export const OtpInput = forwardRef((props, ref) => { const isFocusedContainer = isFocusedInput || (isFilledLastInput && Boolean(isFocused)); return ( - ((props, ref) => { focusStickBlinkingDuration={focusStickBlinkingDuration} /> ) : ( - + {char && secureTextEntry ? "•" : char} - + )} - + ); })} ((props, ref) => { {...textInputProps} style={[styles.hiddenInput, textInputProps?.style]} /> - + ); }); diff --git a/src/OtpInput/OtpInput.types.ts b/src/OtpInput/OtpInput.types.ts index 2e43bcd..4ecb330 100644 --- a/src/OtpInput/OtpInput.types.ts +++ b/src/OtpInput/OtpInput.types.ts @@ -16,6 +16,7 @@ export interface OtpInputProps { disabled?: boolean; textInputProps?: TextInputProps; type?: "alpha" | "numeric" | "alphanumeric"; + useAnimatedComponents?: boolean; } export interface OtpInputRef {