import React from 'react'; import { type ListRenderItemInfo, StyleSheet } from 'react-native'; import type { SelectOption, SelectProps } from '../../../../../types/select'; import { BottomSheetFlatList, useBottomSheet } from '../../../../bottom-sheet/public'; import { withZoraThemeScope } from '../../../../theme/adapters/inbound/withZoraThemeScope'; import { SelectField } from '../../composition/SelectField'; import { SelectOptionRow } from '../../composition/SelectOptionRow'; import { SelectTrigger } from '../../composition/SelectTrigger'; import { useSelectController } from '../../composition/useSelectController'; const SELECT_SHEET_MAX_HEIGHT = 480; /*** Renders Select with BottomSheetFlatList presentation on native platforms. */ export const Select = withZoraThemeScope(SelectInner); /*** Connects shared Select state and controls to the native BottomSheet host. */ function SelectInner({ themeId: _themeId, mode: _mode, ...props }: SelectProps) { const { dismiss, present } = useBottomSheet(); const { select, selectedOption, value } = useSelectController(props); const passive = props.interactionPolicy === 'passive'; const { disabled, interactionPolicy, options, readOnly, testID } = props; const listData = React.useMemo(() => [...options], [options]); const handleSelect = React.useCallback( (nextValue: TValue) => { select(nextValue); dismiss(); }, [dismiss, select], ); const renderOption = React.useCallback( ({ item }: ListRenderItemInfo>) => ( ), [handleSelect, interactionPolicy, testID, value], ); const openSelect = React.useCallback(() => { if (disabled || readOnly || passive) return; present({ contentMode: 'direct', maxDynamicContentSize: SELECT_SHEET_MAX_HEIGHT, content: ( item.value} renderItem={renderOption} /> ), }); }, [disabled, listData, passive, present, readOnly, renderOption]); return ( ); } const styles = StyleSheet.create({ listContent: { padding: 16, }, });