import React, { memo, useRef } from 'react'; import isEqual from 'react-fast-compare'; import { FlatList } from 'react-native'; import { ERRORS, logError } from '../../helpers'; import { NoOptions } from '../no-options'; import type { FlatOptionsListProps } from './flat-options-list.types'; export const FlatOptionsList = memo( ({ renderItem, getItemLayout, resolvedData, flatListProps, initialScrollIndex, accessibilityState, disabled, }: FlatOptionsListProps) => { const flatListRef = useRef(null); const scrollToIndex = () => { if ( flatListRef.current && initialScrollIndex >= 0 && initialScrollIndex < resolvedData.length ) { try { flatListRef.current.scrollToIndex({ animated: false, index: initialScrollIndex, }); } catch { logError(ERRORS.SCROLL_TO_LOCATION); } } }; return ( } scrollEnabled={!disabled} {...flatListProps} data={resolvedData} getItemLayout={getItemLayout} renderItem={renderItem} keyExtractor={({ value }) => value} onLayout={scrollToIndex} /> ); }, isEqual, ); FlatOptionsList.displayName = 'FlatOptionsList';