From 7a78f94dba272f013bc3b81408a9664225bd61bf Mon Sep 17 00:00:00 2001 From: Youssef Henna Date: Mon, 23 Feb 2026 10:53:29 +0100 Subject: [PATCH 1/2] ios picker internal state inside Portal --- .../components/Picker/NativePicker.ios.tsx | 171 ++++++++++++++++++ .../src/components/Picker/NativePicker.tsx | 50 +---- 2 files changed, 177 insertions(+), 44 deletions(-) create mode 100644 packages/core/src/components/Picker/NativePicker.ios.tsx diff --git a/packages/core/src/components/Picker/NativePicker.ios.tsx b/packages/core/src/components/Picker/NativePicker.ios.tsx new file mode 100644 index 000000000..f0dcba935 --- /dev/null +++ b/packages/core/src/components/Picker/NativePicker.ios.tsx @@ -0,0 +1,171 @@ +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 { 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: any; + 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 ( + +