import React, { useState } from 'react'; import { ScrollView, Alert, Text } from 'react-native'; import { Stepper, Space } from '@xrnjs/ui'; import Card from '_global/Card'; const EventHandling: React.FC = () => { const [value1, setValue1] = useState(5); const [value2, setValue2] = useState(0); const [logs, setLogs] = useState([]); const addLog = (message: string) => { setLogs((prev) => [...prev.slice(-4), message]); }; const handleBeforeChange = async ( value?: number | string ): Promise => { return new Promise((resolve) => { Alert.alert('确认修改', `是否将值修改为 ${value}?`, [ { text: '取消', onPress: () => resolve(false) }, { text: '确认', onPress: () => resolve(true) }, ]); }); }; return ( addLog(`onChange: ${val}`)} onFocus={() => addLog('onFocus')} onBlur={() => addLog('onBlur')} onPlus={(e, val) => addLog(`onPlus: ${val}`)} onMinus={(e, val) => addLog(`onMinus: ${val}`)} /> 事件日志: {logs.map((log, index) => ( {log} ))} 修改值时会弹出确认框 value && setValue1} beforeChange={handleBeforeChange} /> 只允许偶数值 value && setValue2} beforeChange={(val) => { const num = Number(val); return num % 2 === 0; }} /> ); }; export default EventHandling;