import React, { useState } from 'react'; import { View, Text, ScrollView, StyleSheet, } from 'react-native'; import { Ux4gOtpInput } from '../components/otp-input/OtpInput'; import { Ux4gButton } from '../components/button/Button'; import { useUx4gTheme } from '../theme/Ux4gThemeContext'; export const OtpInputShowcase: React.FC = () => { const theme = useUx4gTheme(); const colors = theme.colors; const [otpValue1, setOtpValue1] = useState('123'); const [otpValue2, setOtpValue2] = useState(''); const [otpValue3, setOtpValue3] = useState('543210'); const [otpValue4, setOtpValue4] = useState(''); const [otpValue5, setOtpValue5] = useState('9876'); const [timerResetKey, setTimerResetKey] = useState(0); const [completedMsg, setCompletedMsg] = useState(''); const cardStyle = [ styles.card, { backgroundColor: theme.isDark ? '#1F1F1F' : '#FFFFFF', borderColor: theme.isDark ? '#333333' : '#E4E4E7', }, ]; const titleStyle = [ styles.sectionTitle, { color: theme.isDark ? '#F4F4F5' : '#18181B' }, ]; const subtitleStyle = [ styles.subText, { color: theme.isDark ? '#A1A1AA' : '#71717A' }, ]; return ( 🔢 OTP Input Component (`Ux4gOtpInput`) Direct React Native port of Flutter `otp_input.dart`. Supports single-digit boxes, blinking focus cursor, auto-countdown resend timer, attempt counter, obscure password mode, statuses (`error`, `warning`, `success`, `locked`), and full paste handling. {/* 1. Basic 6-Digit & 4-Digit OTP Inputs */} 1. Basic 6-Digit & 4-Digit OTP Inputs Standard OTP verification fields with interactive typing, backspace traversal, and completion callbacks. setCompletedMsg(`6-Digit OTP Completed: ${code}`)} /> setCompletedMsg(`4-Digit PIN Completed: ${code}`)} /> {completedMsg ? ( ✅ {completedMsg} ) : null} {/* 2. Auto-Countdown Resend Timer */} 2. Auto-Countdown Resend Timer (`autoCountdownSeconds`) Counts down `mm:ss` automatically. When expired, switches caption to pressable "Resend OTP". { setOtpValue2(''); setTimerResetKey((prev) => prev + 1); }} /> { setOtpValue2(''); setTimerResetKey((prev) => prev + 1); }} /> {/* 3. Input Status States */} 3. Status States (`status`) Displays contextual validation feedback (`error`, `warning`, `success`, `locked`, `disabled`). {/* Error Status */} {}} status="error" captionVariant="plain" captionText="⚠️ Invalid OTP code. Please try again." /> {/* Success Status */} {/* Locked Status */} {}} status="locked" captionVariant="locked" captionLeadingText="Locked for 28:43" captionTrailingText="Resend OTP" onCaptionTrailingTap={() => {}} /> {/* Disabled Status */} {}} enabled={false} /> {/* 4. Obscure Password Mode & Attempt Counter */} 4. Obscure Mode & Attempt Counter Secure PIN entry obscuring characters with '•' and attempt counter timers. {/* Obscure Mode */} {/* Attempt Counter with Timer */} {}} status="error" captionVariant="attemptWithTimer" captionLeadingText="Attempt 2 of 3" captionTrailingText="Resend in 00:17" /> ); }; const styles = StyleSheet.create({ container: { flex: 1, }, contentContainer: { padding: 16, paddingBottom: 40, }, header: { marginBottom: 16, }, title: { fontSize: 22, fontWeight: '800', marginBottom: 6, }, subText: { fontSize: 14, lineHeight: 20, }, card: { borderWidth: 1, borderRadius: 16, padding: 16, marginBottom: 16, }, sectionTitle: { fontSize: 16, fontWeight: '700', marginBottom: 4, }, stackGroup: { marginTop: 14, gap: 14, }, msgBox: { padding: 10, borderRadius: 8, backgroundColor: '#F6FFED', borderColor: '#B7EB8F', borderWidth: 1, }, });