{"version":3,"sources":["PickerIOS.ios.js"],"names":["useMergeRefs","refs","React","useCallback","current","ref","PickerIOSItem","props","PickerIOSWithForwardedRef","forwardRef","PickerIOS","forwardedRef","children","selectedValue","selectionColor","themeVariant","testID","itemStyle","numberOfLines","onChange","onValueChange","style","nativePickerRef","useRef","nativeSelectedIndex","setNativeSelectedIndex","useState","value","items","selectedIndex","useMemo","Children","toArray","map","child","index","String","label","textColor","color","parsedNumberOfLines","Math","round","useLayoutEffect","jsValue","forEach","shouldUpdateNativePicker","global","nativeFabricUIManager","iOSPickerCommands","setNativeProps","_onChange","event","nativeEvent","newValue","newIndex","styles","pickerIOS","StyleSheet","create","height","Item"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;;;;;;AAEA;;AACA;;AACA;;;;;;AAoDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,YAAT,CAAyB,GAAGC,IAA5B,EAA2E;AACzE,SAAOC,KAAK,CAACC,WAAN,CACJC,OAAD,IAAgB;AACd,SAAK,MAAMC,GAAX,IAAkBJ,IAAlB,EAAwB;AACtB,UAAII,GAAG,IAAI,IAAX,EAAiB;AACf,YAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,UAAAA,GAAG,CAACD,OAAD,CAAH;AACD,SAFD,MAEO;AACLC,UAAAA,GAAG,CAACD,OAAJ,GAAcA,OAAd;AACD;AACF;AACF;AACF,GAXI,EAYL,CAAC,GAAGH,IAAJ,CAZK,CAYM;AAZN,GAAP;AAcD,C,CAED;;;AACA,MAAMK,aAAmC,GAAIC,KAAD,IAA4B;AACtE,SAAO,IAAP;AACD,CAFD;;AAIA,MAAMC,yBAGL,gBAAGN,KAAK,CAACO,UAAN,CAAiB,SAASC,SAAT,CAAmBH,KAAnB,EAA0BI,YAA1B,EAAoD;AACvE,QAAM;AACJC,IAAAA,QADI;AAEJC,IAAAA,aAFI;AAGJC,IAAAA,cAHI;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N,CACfiD,KAAD,IAAuB;AACrBjC,IAAAA,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGiC,KAAH,CAAR;AACAhC,IAAAA,aAAa,SAAb,IAAAA,aAAa,WAAb,YAAAA,aAAa,CAAGgC,KAAK,CAACC,WAAN,CAAkBC,QAArB,EAA+BF,KAAK,CAACC,WAAN,CAAkBE,QAAjD,CAAb;AACA9B,IAAAA,sBAAsB,CAAC;AAACE,MAAAA,KAAK,EAAEyB,KAAK,CAACC,WAAN,CAAkBE;AAA1B,KAAD,CAAtB;AACD,GALe,EAMhB,CAACpC,QAAD,EAAWC,aAAX,CANgB,CAAlB;;AASA,sBACE,oBAAC,iBAAD;AAAM,IAAA,KAAK,EAAEC;AAAb,kBACE,oBAAC,iCAAD;AACE,IAAA,GAAG,EAAEhB,GADP;AAEE,IAAA,YAAY,EAAEU,YAFhB;AAGE,IAAA,MAAM,EAAEC,MAHV;AAIE,IAAA,KAAK,EAAE,CAACwC,MAAM,CAACC,SAAR,EAAmBxC,SAAnB,CAJT,CAKE;AALF;AAME,IAAA,KAAK,EAAEW,KANT;AAOE,IAAA,QAAQ,EAAEuB,SAPZ;AAQE,IAAA,aAAa,EAAEX,mBARjB;AASE,IAAA,aAAa,EAAEX,aATjB;AAUE,IAAA,cAAc,EAAE,+BAAaf,cAAb;AAVlB,IADF,CADF;AAgBD,CA5GG,CAHJ;;AAiHA,MAAM0C,MAAM,GAAGE,wBAAWC,MAAX,CAAkB;AAC/BF,EAAAA,SAAS,EAAE;AACT;AACA;AACA;AACAG,IAAAA,MAAM,EAAE;AAJC;AADoB,CAAlB,CAAf,C,CASA;;;AACApD,yBAAyB,CAACqD,IAA1B,GAAiCvD,aAAjC;eAEeE,yB","sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n *\n * This is a controlled component version of RNCPickerIOS\n *\n * @format\n * @flow\n */\n\n'use strict';\n\nimport * as React from 'react';\nimport {processColor, StyleSheet, View} from 'react-native';\nimport RNCPickerNativeComponent, {\n Commands as iOSPickerCommands,\n} from './RNCPickerNativeComponent';\nimport type {SyntheticEvent} from 'react-native/Libraries/Types/CoreEventTypes';\nimport type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type {\n ColorValue,\n TextStyleProp,\n} from 'react-native/Libraries/StyleSheet/StyleSheet';\nimport type {Element, ChildrenArray} from 'react';\n\ntype PickerIOSChangeEvent = SyntheticEvent<\n $ReadOnly<{|\n newValue: number | string,\n newIndex: number,\n |}>,\n>;\n\ntype RNCPickerIOSItemType = $ReadOnly<{|\n label: ?Label,\n value: ?(number | string),\n textColor: ?ColorValue,\n testID: ?string,\n|}>;\n\ntype Label = Stringish | number;\n\ntype Props = $ReadOnly<{|\n ...ViewProps,\n // $FlowFixMe\n children: ChildrenArray>,\n itemStyle?: ?TextStyleProp,\n numberOfLines: ?number,\n onChange?: ?(event: PickerIOSChangeEvent) => mixed,\n onValueChange?: ?(itemValue: string | number, itemIndex: number) => mixed,\n selectedValue: ?(number | string),\n selectionColor: ?string,\n themeVariant: ?string,\n|}>;\n\ntype ItemProps = $ReadOnly<{|\n label: ?Label,\n value?: ?(number | string),\n color?: ?ColorValue,\n testID?: ?string,\n|}>;\n\ntype CallbackRef = (T) => mixed;\ntype ObjectRef = {current: T, ...};\n\ntype Ref = CallbackRef | ObjectRef;\n\n/**\n * Constructs a new ref that forwards new values to each of the given refs. The\n * given refs will always be invoked in the order that they are supplied.\n *\n * WARNING: A known problem of merging refs using this approach is that if any\n * of the given refs change, the returned callback ref will also be changed. If\n * the returned callback ref is supplied as a `ref` to a React element, this may\n * lead to problems with the given refs being invoked more times than desired.\n */\nfunction useMergeRefs(...refs: $ReadOnlyArray>): CallbackRef {\n return React.useCallback(\n (current: T) => {\n for (const ref of refs) {\n if (ref != null) {\n if (typeof ref === 'function') {\n ref(current);\n } else {\n ref.current = current;\n }\n }\n }\n },\n [...refs], // eslint-disable-line react-hooks/exhaustive-deps\n );\n}\n\n// $FlowFixMe\nconst PickerIOSItem: RNCPickerIOSItemType = (props: ItemProps): null => {\n return null;\n};\n\nconst PickerIOSWithForwardedRef: React.AbstractComponent<\n Props,\n React.ElementRef,\n> = React.forwardRef(function PickerIOS(props, forwardedRef): React.Node {\n const {\n children,\n selectedValue,\n selectionColor,\n themeVariant,\n testID,\n itemStyle,\n numberOfLines,\n onChange,\n onValueChange,\n style,\n } = props;\n\n const nativePickerRef = React.useRef | null>(null);\n\n // $FlowFixMe\n const ref = useMergeRefs(nativePickerRef, forwardedRef);\n\n const [nativeSelectedIndex, setNativeSelectedIndex] = React.useState({\n value: null,\n });\n\n const [items, selectedIndex] = React.useMemo(() => {\n // eslint-disable-next-line no-shadow\n let selectedIndex = 0;\n // eslint-disable-next-line no-shadow\n const items = React.Children.toArray<$FlowFixMe>(children).map(\n (child, index) => {\n if (child === null) {\n return null;\n }\n if (String(child.props.value) === String(selectedValue)) {\n selectedIndex = index;\n }\n return {\n value: String(child.props.value),\n label: String(child.props.label),\n textColor: processColor(child.props.color),\n testID: child.props.testID,\n };\n },\n );\n return [items, selectedIndex];\n }, [children, selectedValue]);\n\n let parsedNumberOfLines = Math.round(numberOfLines ?? 1);\n if (parsedNumberOfLines < 1) {\n parsedNumberOfLines = 1;\n }\n\n React.useLayoutEffect(() => {\n let jsValue = 0;\n React.Children.toArray<$FlowFixMe>(children).forEach(function (\n child: $FlowFixMe,\n index: number,\n ) {\n if (String(child.props.value) === String(selectedValue)) {\n jsValue = index;\n }\n });\n // This is necessary in case native updates the switch and JS decides\n // that the update should be ignored and we should stick with the value\n // that we have in JS.\n const shouldUpdateNativePicker =\n nativeSelectedIndex.value != null &&\n nativeSelectedIndex.value !== jsValue;\n if (shouldUpdateNativePicker && nativePickerRef.current) {\n if (global?.nativeFabricUIManager) {\n iOSPickerCommands.setNativeSelectedIndex(\n nativePickerRef.current,\n jsValue,\n );\n } else {\n nativePickerRef.current.setNativeProps({\n selectedIndex: jsValue,\n });\n }\n }\n }, [selectedValue, nativeSelectedIndex, children]);\n\n const _onChange = React.useCallback(\n (event: $FlowFixMe) => {\n onChange?.(event);\n onValueChange?.(event.nativeEvent.newValue, event.nativeEvent.newIndex);\n setNativeSelectedIndex({value: event.nativeEvent.newIndex});\n },\n [onChange, onValueChange],\n );\n\n return (\n \n \n \n );\n});\n\nconst styles = StyleSheet.create({\n pickerIOS: {\n // The picker will conform to whatever width is given, but we do\n // have to set the component's height explicitly on the\n // surrounding view to ensure it gets rendered.\n height: 216,\n },\n});\n\n// $FlowFixMe\nPickerIOSWithForwardedRef.Item = PickerIOSItem;\n\nexport default PickerIOSWithForwardedRef;\n"]}