import React, { useState } from 'react'; import { Text } from 'react-native'; import { Space, Select, SelectProps } from '@xrnjs/ui'; import Card from '_global/Card'; import { styles } from './style'; const options = [ { label: '选项一', value: 'option1', }, { label: '选项二', value: 'option2', }, { label: '选项三', value: 'option3', }, ]; const longOptions = new Array(20).fill(0).map((_, index) => ({ label: `选项${index + 1}`, value: `option${index + 1}`, })); const LoadingSelect = ({ type = Select.Type.radio, showSearch, isLong, isFlatList, }: { type?: SelectProps['type']; showSearch?: boolean; isLong?: boolean; isFlatList?: boolean; }) => { const [op, setOp] = useState<{ label: string; value: string }[]>([]); const [visible, setVisible] = useState(false); const [value, setValue] = useState(); const [displayValue, setDisplayValue] = useState(); const onChange = (selectedValue: string | string[]) => { setValue(selectedValue); if (typeof selectedValue === 'string') { const selectedOption = options.find((opt) => opt.value === selectedValue); setDisplayValue(selectedOption?.label); setVisible(false); return; } }; const handleConfirm = (selectedValue: string | string[]) => { if (typeof selectedValue === 'string') return; const selectedOptions = selectedValue.map((val) => isLong ? longOptions.find((opt) => opt.value === val) : options.find((opt) => opt.value === val) ); setDisplayValue(selectedOptions.map((opt) => opt?.label).join(', ')); setVisible(false); }; const onClear = () => { setValue(''); setDisplayValue(''); }; return ( <>