/** * 注册步骤1:输入邮箱 * 包含邮箱输入框和获取验证码按钮 */ import React, { useState } from 'react'; import { View, Text, StyleSheet, TextInput, TouchableOpacity, } from 'react-native'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { useAppColors, type AppColors } from '../../theme'; import { RegisterStepProps } from './types'; export const RegisterStep1Email: React.FC = ({ formData, updateFormData, onNext, colors: propColors, sendingCode, countdown, onSendCode, }) => { const colors = propColors || useAppColors(); const styles = createStyles(colors); const [emailError, setEmailError] = useState(''); const validateEmail = (email: string): boolean => { if (!email.trim()) { setEmailError('请输入邮箱'); return false; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { setEmailError('请输入正确的邮箱地址'); return false; } setEmailError(''); return true; }; const handleSendCode = async () => { if (!validateEmail(formData.email)) { return; } if (onSendCode) { const success = await onSendCode(formData.email); if (success) { onNext(); } } }; return ( {/* 邮箱输入框 */} 邮箱 { updateFormData({ email: text }); if (emailError) setEmailError(''); }} autoCapitalize="none" autoCorrect={false} keyboardType="email-address" editable={!sendingCode} /> {formData.email.length > 0 && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email) && ( )} {emailError ? ( {emailError} ) : null} {/* 获取验证码按钮 */} 0) && styles.actionButtonDisabled, ]} onPress={handleSendCode} disabled={sendingCode || (countdown ?? 0) > 0} activeOpacity={0.9} > {sendingCode ? '发送中...' : (countdown ?? 0) > 0 ? `${countdown}秒后重试` : '获取验证码'} ); } function createStyles(colors: AppColors) { return StyleSheet.create({ container: { flex: 1, paddingTop: 20, }, formSection: { marginBottom: 24, }, inputContainer: { marginBottom: 24, }, inputLabel: { fontSize: 14, fontWeight: '500', color: colors.text?.secondary || '#666', marginBottom: 10, }, inputWrapper: { flexDirection: 'row', alignItems: 'center', backgroundColor: colors.background.default, borderRadius: 14, paddingHorizontal: 18, height: 56, borderWidth: 1, borderColor: 'transparent', }, inputWrapperError: { borderColor: colors.error?.main || '#FF4444', }, input: { flex: 1, fontSize: 16, color: colors.text?.primary || '#333', height: 56, }, checkIcon: { marginLeft: 8, }, errorText: { fontSize: 12, color: colors.error?.main || '#FF4444', marginTop: 6, marginLeft: 4, }, actionButton: { height: 56, borderRadius: 14, backgroundColor: colors.primary.main, alignItems: 'center', justifyContent: 'center', marginTop: 8, }, actionButtonDisabled: { opacity: 0.6, }, actionButtonText: { fontSize: 17, fontWeight: '600', color: colors.text.inverse, }, }); } export default RegisterStep1Email;