import React, { useState } from 'react'; import { Text } from 'react-native'; import { Space, Select, SelectInputItem, Toast } from '@xrnjs/ui'; import Card from '_global/Card'; import { styles } from './style'; const options = [ { label: '苹果', value: 'apple', }, { label: '香蕉', value: 'banana', }, { label: '橙子', value: 'orange', }, { label: '葡萄', value: 'grape', }, { label: '西瓜(禁用)', value: 'watermelon', disabled: true, }, ]; const MultipleSelectExample = () => { const [visible, setVisible] = useState(false); const [value, setValue] = useState([]); const [displayValue, setDisplayValue] = useState([]); const setValueAndDisplay = (values: string[] | string) => { if (!Array.isArray(values)) return; setValue(values); const display: SelectInputItem[] = []; values.forEach((v) => { const option = options.find((opt) => opt.value === v); if (option) { display.push({ value: option.value, label: option.label }); } }); setDisplayValue(display); }; const onConfirm = (values: string | string[]) => { setValueAndDisplay(values as string[]); setVisible(false); }; const onClear = () => { setValue([]); setDisplayValue([]); }; const onClose = (item: SelectInputItem) => { const newValues = value.filter((v) => v !== item.value); setValueAndDisplay(newValues); }; const onDisabledPress = (option: any) => { Toast({ position: 'middle', message: `${option.label} 不可选择`, forbidPress: true, }); }; return ( 多选示例