import { useSnapshot } from 'valtio';
import { FlatList, View, Modal } from 'react-native';
import {
FlexView,
IconBox,
IconLink,
Image,
SearchBar,
Separator,
Spacing,
Text,
useCustomDimensions,
useTheme
} from '@reown/appkit-ui-react-native';
import { AssetController, AssetUtil, ConnectionsController } from '@reown/appkit-core-react-native';
import { Placeholder } from '../w3m-placeholder';
import styles from './styles';
interface SelectorModalProps {
title?: string;
visible: boolean;
onClose: () => void;
items: any[];
selectedItem?: any;
renderItem: ({ item }: { item: any }) => React.ReactElement;
keyExtractor: (item: any, index: number) => string;
onSearch: (value: string) => void;
itemHeight?: number;
showNetwork?: boolean;
searchPlaceholder?: string;
emptyTitle?: string;
emptyDescription?: string;
}
const SEPARATOR_HEIGHT = Spacing.s;
export function SelectorModal({
title,
visible,
onClose,
items,
selectedItem,
renderItem,
onSearch,
searchPlaceholder,
keyExtractor,
itemHeight,
showNetwork,
emptyTitle = 'No tokens found',
emptyDescription = "There's no available tokens for this network"
}: SelectorModalProps) {
const Theme = useTheme();
const { maxHeight } = useCustomDimensions();
const { activeNetwork } = useSnapshot(ConnectionsController.state);
const { networkImages } = useSnapshot(AssetController.state);
const networkImage = AssetUtil.getNetworkImage(activeNetwork, networkImages);
const renderSeparator = () => {
return ;
};
return (
}
ListHeaderComponent={
<>
{!!title && {title}}
{showNetwork ? (
networkImage ? (
) : (
)
) : (
)}
{selectedItem ? (
{renderItem({ item: selectedItem })}
) : null}
>
}
contentContainerStyle={styles.listContent}
ItemSeparatorComponent={renderSeparator}
keyExtractor={keyExtractor}
getItemLayout={
itemHeight
? (_, index) => ({
length: itemHeight + SEPARATOR_HEIGHT,
offset: (itemHeight + SEPARATOR_HEIGHT) * index,
index
})
: undefined
}
/>
);
}