/** * WheelPickerModal — iOS-native UIPickerView style wheel via @react-native-picker/picker. * * Pattern: * 1. User taps a row → setVisible(true) * 2. Modal slides up bottom-sheet with native iOS wheel + Done/Cancel * 3. Wheel scrolls through options, current selection highlighted * 4. User taps "Fertig" → onSelect(value), modal closes * 5. User taps "Abbrechen" or outside → modal closes without change * * Use für: lange Listen (Geburtsjahr 91 items, Bundesland 16, Stadt 30-50/Bundesland). * Für kurze Listen (3-7 items) bleibt ActionSheet besser (siehe useNativeActionSheet). */ import { useEffect, useState } from 'react'; import { Modal, View, Text, Pressable } from 'react-native'; import { Picker } from '@react-native-picker/picker'; import { useColors } from '../lib/theme'; type Option = { value: T; label: string }; type Props = { visible: boolean; title: string; options: Option[]; value: T | null; onSelect: (value: T) => void; onClose: () => void; }; export function WheelPickerModal({ visible, title, options, value, onSelect, onClose, }: Props) { const colors = useColors(); // Tracks the wheel's current selection (separate from confirmed value). // Initialized from `value` prop on each open. const [tempValue, setTempValue] = useState(value); useEffect(() => { if (visible) { // First-open default: if no current value, pick first option. setTempValue(value ?? options[0]?.value ?? null); } }, [visible, value, options]); function handleConfirm() { if (tempValue !== null && tempValue !== undefined) { onSelect(tempValue); } onClose(); } return ( {}}> {/* Header: Cancel / Title / Done */} Abbrechen {title} Fertig {/* Wheel — native iOS UIPickerView */} setTempValue(v as T)} style={{ width: '100%' }} itemStyle={{ fontSize: 18, color: colors.text }} > {options.map((opt) => ( ))} ); }