import React from 'react'; import type { SectionListRenderItemInfo } from 'react-native'; import type { BaseOptionListProps } from '../BaseOptionList'; import BaseOptionList from '../BaseOptionList'; import Option from './Option'; import type { MultiSelectProps } from '.'; import type { SelectOptionType, SectionType } from '../types'; import { isOptionSelected } from './utils'; import { deepCompareValue } from '../../../utils/helpers'; type OptionListProps> = Pick< MultiSelectProps, | 'keyExtractor' | 'loading' | 'onEndReached' | 'onQueryChange' | 'value' | 'renderOption' > & { onPress: (value: V[]) => void; } & BaseOptionListProps; const OptionList = >({ keyExtractor, loading, onEndReached, onPress, onQueryChange, sections, renderOption, value, sectionListRef, ...rest }: OptionListProps) => { const renderItem = (info: SectionListRenderItemInfo) => { const { item } = info; const selected = isOptionSelected(value, item); const onItemPress = () => { if (isOptionSelected(value, item)) { onPress(value.filter((val) => !deepCompareValue(val, item.value))); } else { onPress([...value, item.value]); } }; return renderOption ? ( renderOption({ ...info, selected, onPress: onItemPress }) ) : (