import { BottomSheetTextInput } from "@gorhom/bottom-sheet"; import React, { useCallback, useImperativeHandle, useRef } from "react"; import { type StyleProp, StyleSheet, Text, type TextInputProps, View, type ViewStyle, } from "react-native"; interface PinInputProps extends Omit { value: string; onChangeText: (text: string) => void; length?: number; autoFocus?: boolean; style?: StyleProp; } export interface PinInputRef { focus: () => void; } const PinInputComponent = React.forwardRef( (props, ref) => { const { value, onChangeText, length = 6, style, autoFocus, ...rest } = props; const inputRef = useRef(null); const activeIndex = value.length; const handlePress = useCallback(() => { inputRef.current?.focus(); }, []); useImperativeHandle( ref, () => ({ focus: () => inputRef.current?.focus(), }), [], ); return ( {Array(length) .fill(0) .map((_, i) => ( {value[i]} {i === activeIndex && } ))} ); }, ); PinInputComponent.displayName = "PinInput"; export const PinInput = PinInputComponent; const styles = StyleSheet.create({ container: { width: "100%", }, hiddenInput: { position: "absolute", width: 1, height: 1, opacity: 0, }, cells: { flexDirection: "row", justifyContent: "space-between", width: "100%", }, cell: { width: 40, height: 48, borderWidth: 1, borderColor: "#374151", borderRadius: 8, alignItems: "center", justifyContent: "center", backgroundColor: "#1F2937", }, activeCell: { borderColor: "#6366F1", }, filledCell: { borderColor: "#4B5563", }, digit: { fontSize: 24, color: "white", fontWeight: "500", }, cursor: { position: "absolute", width: 2, height: 24, backgroundColor: "#6366F1", }, });