import React, { useCallback, useMemo } from 'react'; import { FlatListProps, ListRenderItem, StyleProp, TextStyle, ViewStyle } from 'react-native'; import useSelectorItemsNucleon from './nucleons/useSelectorPropsNucleon'; import { BottomSheetFlatList } from '@gorhom/bottom-sheet'; import UIRadioItemAtom, { RADIO_ITEM_HEIGHT } from './UIRadioItemAtom'; import selectedRadioItemContextAtom from './selectedRadioItemContextAtom'; import BoxNucleon from './nucleons/BoxNucleon'; import { useSpacing } from '@mobily/stacks'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { SelectorItem, SelectorListProps } from './nucleons/types'; export interface RadioListControlProps extends SelectorListProps { style?: StyleProp; labelStyle?: | StyleProp | ((item: SelectorItem, index: number) => StyleProp); } function extractKey(item: Required>, index: number) { return `${item.value}-${index}`; } const getItemLayout: FlatListProps< Required> >['getItemLayout'] = function getItemLayout(data, index) { return { index, length: RADIO_ITEM_HEIGHT, offset: RADIO_ITEM_HEIGHT * index }; }; export default function UIRadioListControlMolecule({ items, selectedValue, onSelectedValueChange, style, labelStyle }: RadioListControlProps) { const normalizedItems = useSelectorItemsNucleon(items); const spacing = useSpacing(2); const itemStyle = useMemo(() => ({ paddingHorizontal: spacing }), [spacing]); const { bottom: safeBottom } = useSafeAreaInsets(); const contentContainerStyle = useMemo( () => ({ paddingTop: spacing, paddingBottom: spacing + safeBottom }), [safeBottom, spacing] ); const listRenderItem: ListRenderItem>> = useCallback( ({ item, index }) => { const syntheticLabelStyle = typeof labelStyle === 'function' ? labelStyle(item, index) : labelStyle; const { label, value } = item; return ( ); }, [labelStyle, onSelectedValueChange, itemStyle] ); return ( ); }