|
| 1 | +import { BottomSheetFlashList } from '@suite-native/atoms'; |
| 2 | +import { Translation } from '@suite-native/intl'; |
| 3 | + |
| 4 | +import { SearchableSheetHeader } from '../SearchableSheetHeader'; |
| 5 | +import { CountryListEmptyComponent } from './CountryListEmptyComponent'; |
| 6 | +import { COUNTRY_LIST_ITEM_HEIGHT, CountryListItem } from './CountryListItem'; |
| 7 | +import { Country } from '../../../types'; |
| 8 | + |
| 9 | +export type CountrySheetProps = { |
| 10 | + isVisible: boolean; |
| 11 | + onClose: () => void; |
| 12 | + onCountrySelect: (symbol: Country) => void; |
| 13 | + selectedCountryId?: string; |
| 14 | +}; |
| 15 | + |
| 16 | +const mockCountries: Country[] = [ |
| 17 | + { id: 'us', name: 'United States', flag: 'flag' }, |
| 18 | + { id: 'cz', name: 'Czech Republic', flag: 'flagCheckered' }, |
| 19 | + { id: 'sk', name: 'Slovakia', flag: 'flag' }, |
| 20 | + { id: 'de', name: 'Germany', flag: 'flagCheckered' }, |
| 21 | + { id: 'fr', name: 'France', flag: 'flag' }, |
| 22 | + { id: 'es', name: 'Spain', flag: 'flagCheckered' }, |
| 23 | + { id: 'it', name: 'Italy', flag: 'flag' }, |
| 24 | + { id: 'pl', name: 'Poland', flag: 'flagCheckered' }, |
| 25 | + { id: 'hu', name: 'Hungary', flag: 'flag' }, |
| 26 | + { id: 'at', name: 'Austria', flag: 'flagCheckered' }, |
| 27 | + { id: 'ch', name: 'Switzerland', flag: 'flag' }, |
| 28 | +]; |
| 29 | + |
| 30 | +const keyExtractor = (item: Country) => item.id; |
| 31 | +const getEstimatedListHeight = (itemsCount: number) => itemsCount * COUNTRY_LIST_ITEM_HEIGHT; |
| 32 | + |
| 33 | +export const CountrySheet = ({ |
| 34 | + isVisible, |
| 35 | + onClose, |
| 36 | + onCountrySelect, |
| 37 | + selectedCountryId, |
| 38 | +}: CountrySheetProps) => { |
| 39 | + const onCountrySelectCallback = (country: Country) => { |
| 40 | + onCountrySelect(country); |
| 41 | + onClose(); |
| 42 | + }; |
| 43 | + |
| 44 | + const data: Country[] = mockCountries; |
| 45 | + |
| 46 | + return ( |
| 47 | + <BottomSheetFlashList<Country> |
| 48 | + isVisible={isVisible} |
| 49 | + onClose={onClose} |
| 50 | + ListEmptyComponent={<CountryListEmptyComponent />} |
| 51 | + handleComponent={() => ( |
| 52 | + <SearchableSheetHeader |
| 53 | + onClose={onClose} |
| 54 | + title={<Translation id="moduleTrading.countrySheet.title" />} |
| 55 | + /> |
| 56 | + )} |
| 57 | + renderItem={({ item }) => ( |
| 58 | + <CountryListItem |
| 59 | + {...item} |
| 60 | + onPress={() => onCountrySelectCallback(item)} |
| 61 | + isSelected={item.id === selectedCountryId} |
| 62 | + /> |
| 63 | + )} |
| 64 | + data={data} |
| 65 | + estimatedListHeight={getEstimatedListHeight(data.length)} |
| 66 | + estimatedItemSize={COUNTRY_LIST_ITEM_HEIGHT} |
| 67 | + keyExtractor={keyExtractor} |
| 68 | + /> |
| 69 | + ); |
| 70 | +}; |
0 commit comments