import React, { useCallback, useMemo, useState } from "react"; import { Pressable, View } from "react-native"; import { IconButton, Menu, useTheme } from "react-native-paper"; import AppInput from "./AppInput"; export interface Item { value: string; label: string; color?: string; icon?: string; } function Select({ value, onChange, items, label, }: { value: string; onChange: (value: string) => void; items: Item[]; label?: string; }) { const [show, setShow] = useState(false); const { colors } = useTheme(); let menuButton: React.Ref = null; const selected = useMemo( () => items.find((item) => item.value === value) || items[0], [items, value] ); const press = useCallback( (newValue: string) => { onChange(newValue); setShow(false); }, [onChange] ); return ( setShow(false)} anchor={ setShow(true)}> setShow(true)} /> } > {items.map((item) => ( press(item.value)} titleStyle={{ color: item.color || colors.onSurface }} leadingIcon={item.icon} /> ))} ); } export default React.memo(Select);