/* eslint-disable react-native/no-inline-styles */ import React, { useEffect, useRef } from 'react'; import { FlatList, FlatListProps, StyleSheet } from 'react-native'; import DropdownListItem from './DropdownListItem'; import { ItemSeparatorComponent, ListEmptyComponent } from '../Others'; import { TFlatList } from '../../types/index.types'; const DropdownFlatList = ({ options, optionLabel, optionValue, isMultiple, isSearchable, selectedItems, selectedItem, handleMultipleSelections, handleSingleSelection, primaryColor, checkboxControls, listComponentStyles, listIndex, emptyListMessage, listEmptyComponent, ...rest }: any & FlatListProps) => { const flatlistRef = useRef>(null); const scrollToItem = (index: number) => { flatlistRef?.current?.scrollToIndex({ index, animated: true, }); }; useEffect(() => { if (listIndex.itemIndex >= 0) { scrollToItem(listIndex.itemIndex); } }, [listIndex]); const itemSeparator = () => ( ); return ( ) } contentContainerStyle={[ isSearchable ? { paddingTop: 0 } : styles.contentContainerStyle, ]} ItemSeparatorComponent={itemSeparator} renderItem={(item) => _renderItem(item, { optionLabel, optionValue, isMultiple, selectedOption: isMultiple ? selectedItems : selectedItem, onChange: isMultiple ? handleMultipleSelections : handleSingleSelection, scrollToItem, primaryColor, checkboxControls, }) } keyExtractor={(_item, index) => `Options${index}`} ref={flatlistRef} onScrollToIndexFailed={({ index }) => { setTimeout(() => { scrollToItem(index); }, 500); }} {...rest} /> ); }; const _renderItem = ({ item }: any, props: any) => { return ( ); }; const styles = StyleSheet.create({ contentContainerStyle: { paddingTop: 20 }, }); export default DropdownFlatList;