import React from 'react'; import { View, StyleSheet, Text } from 'react-native'; import Form from '../index'; import Radio from '../../Radio'; 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 = { gender: string; city: string; plan: string; theme: string; language: string; notification: string; }; const RadioExamplesDemo: React.FC = () => { const form = Form.useForm({ defaultValues: { gender: '', city: 'beijing', plan: 'basic', theme: '', language: '', notification: '', }, }); const [languageFixed, setLanguageFixed] = React.useState('en-US'); const onSubmit = (data: FormData) => { console.log('Form submitted:', data); Toast( `提交成功!\n性别: ${data.gender}\n城市: ${data.city}\n套餐: ${data.plan}` ); }; const onError = (errors: Record) => { console.log('Form errors:', errors); }; return ( {/* 组合用法示例 */} {/* 快捷用法示例 */} { console.log(e); }} rules={{ required: '请选择城市' }} options={[ { label: '北京', value: 'beijing' }, { label: '上海', value: 'shanghai' }, { label: '深圳', value: 'shenzhen' }, { label: '广州', value: 'guangzhou' }, ]} /> {/* 高级配置示例 */} value !== 'free' || '免费套餐功能有限,建议升级', }} options={[ { label: '免费版', value: 'free' }, { label: '基础版 ¥99/月', value: 'basic' }, { label: '专业版 ¥199/月', value: 'pro' }, { label: '企业版 ¥999/月', value: 'enterprise' }, ]} /> { if (value === 'none') { return '建议至少开启重要通知,以免错过重要信息'; } return true; }, }} options={[ { label: '全部通知', value: 'all' }, { label: '仅重要通知', value: 'important' }, { label: '关闭通知', value: 'none' }, ]} /> {/* 禁用状态示例 */} 当前值:{languageFixed} setLanguageFixed(v as string)} /> ); }; 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 RadioExamplesDemo;