import * as React from "react"; import { StyleSheet, Keyboard } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { Picker as NativePickerComponent } from "@react-native-picker/picker"; import Portal from "../Portal/Portal"; import { Button } from "../Button"; import { useDeepCompareMemo } from "../../utilities"; import { CommonPickerProps, SinglePickerProps, normalizeToPickerOptions, PickerOption, } from "./PickerCommon"; import PickerInputContainer from "./PickerInputContainer"; import { ReadTheme, withTheme } from "@draftbit/theme"; import { IconSlot } from "../../interfaces/Icon"; /** * Duplicated version of NativePicker.tsx for maintaining state inside the Portal container to avoid this issue * https://github.com/react-native-picker/picker/issues/615 */ interface PortalPickerContentProps extends IconSlot { value: string | number | undefined; options: PickerOption[]; placeholder?: string; onValueChange?: (value: string | number) => void; onClose: () => void; theme: ReadTheme; autoDismissKeyboard?: boolean; } const PortalPickerContent: React.FC = ({ value, options, placeholder, onValueChange, onClose, Icon, theme, autoDismissKeyboard = true, }) => { const pickerRef = React.useRef>(null); // Manage value state inside the Portal to avoid stale state issues across the Portal boundary const [internalValue, setInternalValue] = React.useState< string | number | undefined >(value); React.useEffect(() => { setInternalValue(value); }, [value]); React.useEffect(() => { if (autoDismissKeyboard) { Keyboard.dismiss(); } }, [autoDismissKeyboard]); return (