import React, { useState } from 'react'; import { StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native'; import { Dropdown } from 'react-native-element-dropdown'; interface DropdownOption { label: string; value: string; } interface DropdownSelectProps { dropdownOptions: DropdownOption[]; //receive an array of key-value pair objects for dropdown options. Example: { label: '男', value: 'male' },{ label:'女', value: 'female'} placeholder: string; maxHeight?: number; extendedStyle?: StyleProp; onSelect: (value: string) => void; } const DropdownSelect: React.FC = ({ dropdownOptions, placeholder, maxHeight, extendedStyle, onSelect }) => { const [value, setValue] = useState(null); const [isFocus, setIsFocus] = useState(false); return ( setIsFocus(true)} onBlur={() => setIsFocus(false)} onChange={(item) => { setValue(item.value); setIsFocus(false); onSelect(item.value); }} /> ); }; const styles = StyleSheet.create({ container: { flex: 1, maxWidth: '100%', position: 'relative' }, dropdown: { flex: 1, borderColor: '#bbbbbb', borderWidth: 1, borderRadius: 12, zIndex: 10000, paddingRight: 15 }, selectedTextStyle: { color: '#888', fontSize: 16, paddingLeft: 6 }, placeholderStyle: { color: '#888', paddingLeft: 6 } }); export default DropdownSelect;