import React from 'react'; import { View, StyleSheet, Text } from 'react-native'; import Form from '../index'; import Input from '../../Input'; import Button from '../../Button'; import { ScrollView } from 'react-native'; import BottomSafeArea from '../../BottomSafeArea'; import { Fill, Toast } from '@xrnjs/ui'; import Card from '_global/Card'; type FormData = { username: string; email: string; password: string; confirmPassword: string; description: string; feedback: string; }; const InputExamplesDemo: React.FC = () => { const form = Form.useForm({ defaultValues: { username: '', email: '', password: '', confirmPassword: '', description: '', feedback: '', }, }); const [usernameFixed, setUsernameFixed] = React.useState('外部指定的用户名'); const onSubmit = (data: FormData) => { console.log('Form submitted:', data); Toast( `提交成功 用户名: ${data.username}\n邮箱: ${ data.email }\n个人简介: ${data.description.substring(0, 20)}...` ); }; const onError = (errors: Record) => { console.log('Form errors:', errors); }; return ( {/* 组合用法示例 */} {/* 快捷用法示例 */} { const password = form.getValues('password'); return value === password || '两次密码不匹配'; }, }} /> {/* TextArea 示例 */} { if (value && value.length < 5) { return '意见反馈至少需要5个字符'; } return true; }, }} message="您的反馈对我们很重要" /> 当前值:{usernameFixed} setUsernameFixed(v)} /> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f5f5f5', }, scrollContainer: { flex: 1, padding: 20, paddingBottom: 0, }, cardStyle: { marginBottom: 16, }, fixedButtonContainer: { backgroundColor: '#fff', paddingHorizontal: 20, paddingTop: 16, paddingBottom: 30, borderTopWidth: 1, borderTopColor: '#e5e5e5', flexDirection: 'row', justifyContent: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: -2, }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 8, }, buttonSpacer: { width: 20, }, }); export default InputExamplesDemo;