import React from 'react'; import { View, StyleSheet } from 'react-native'; import Form from '../index'; import Input from '../../Input'; import Switch from '../../Switch'; import Button from '../../Button'; import Card from '_global/Card'; import { ScrollView } from 'react-native'; import { BottomSafeArea, Toast } from '@xrnjs/ui'; // 方式1: 使用 withFormItem 高阶组件 const FormSwitch = Form.withFormItem(Switch, 'FormSwitch'); // 方式3: 使用 createFormComponents 批量创建 const FormComponents = Form.createFormComponents({ CustomInput: Input, }); type FormData = { username: string; email: string; category: string; birthday: Date; isVip: boolean; customField: string; }; const HOCExampleDemo: React.FC = () => { const form = Form.useForm({ defaultValues: { username: '', email: '', category: '', birthday: new Date(), isVip: false, customField: '', }, }); const onSubmit = (data: FormData) => { console.log('Form submitted:', data); Toast('提交成功' + JSON.stringify(data, null, 2)); }; const onError = (errors: any) => { console.log('Form errors:', errors); }; return ( value === true || '必须是VIP用户才能继续', }} /> ); }; const styles = StyleSheet.create({ container: { flex: 1, padding: 20, backgroundColor: '#f5f5f5', }, title: { fontSize: 24, fontWeight: 'bold', marginBottom: 20, textAlign: 'center', color: '#333', }, sectionTitle: { fontSize: 16, fontWeight: '600', marginTop: 20, marginBottom: 10, color: '#666', }, cardStyle: { marginBottom: 16, }, buttonContainer: { marginTop: 30, flexDirection: 'row', justifyContent: 'space-around', }, submitButton: { backgroundColor: '#007AFF', paddingHorizontal: 30, }, resetButton: { backgroundColor: '#666', paddingHorizontal: 30, }, infoContainer: { marginTop: 30, padding: 15, backgroundColor: '#e8f4f8', borderRadius: 8, borderLeftWidth: 4, borderLeftColor: '#007AFF', }, infoTitle: { fontSize: 16, fontWeight: 'bold', marginBottom: 8, color: '#333', }, infoText: { fontSize: 14, lineHeight: 20, color: '#666', }, mockSelect: { height: 40, borderWidth: 1, borderColor: '#ddd', borderRadius: 4, paddingHorizontal: 12, justifyContent: 'center', backgroundColor: '#fff', }, mockSelectText: { fontSize: 16, color: '#333', }, mockDatePicker: { height: 40, borderWidth: 1, borderColor: '#ddd', borderRadius: 4, paddingHorizontal: 12, justifyContent: 'center', backgroundColor: '#fff', }, mockDateText: { fontSize: 16, color: '#333', }, }); export default HOCExampleDemo;