import React, { memo, useMemo } from 'react' import type { ListRenderItem } from 'react-native' import { StyleSheet, FlatList, View, useColorScheme } from 'react-native' import * as Animatable from 'react-native-animatable' import { fadeInDownShort, fadeInUpShort } from './helpers' import { theme } from './theme' import type { AutocompleteDropdownItem, IAutocompleteDropdownProps } from './types' interface DropdownProps extends Omit { ListEmptyComponent: React.ReactElement renderItem: ListRenderItem } export const Dropdown = memo((props: DropdownProps) => { const { dataSet, suggestionsListMaxHeight, renderItem, ListEmptyComponent, ItemSeparatorComponent, direction, theme, ...rest } = props const themeName = theme || useColorScheme() const styles = useMemo(() => getStyles(themeName || 'light'), [themeName]) const defaultItemSeparator = useMemo(() => { return () => }, [styles.itemSeparator]) return ( item.id} ListEmptyComponent={ListEmptyComponent} ItemSeparatorComponent={ItemSeparatorComponent ?? defaultItemSeparator} {...rest.flatListProps} /> ) }) const getStyles = (themeName: 'light' | 'dark' = 'light') => StyleSheet.create({ container: {}, listContainer: { backgroundColor: theme[themeName].suggestionsListBackgroundColor, width: '100%', zIndex: 9, borderRadius: 5, shadowColor: theme[themeName || 'light'].shadowColor, shadowOffset: { width: 0, height: 12, }, shadowOpacity: 0.3, shadowRadius: 15.46, elevation: 20, }, itemSeparator: { height: 1, width: '100%', backgroundColor: theme[themeName || 'light'].itemSeparatorColor, }, })