2020-02-11 14:01:35 +00:00
|
|
|
import React from 'react';
|
2022-09-09 18:23:00 +00:00
|
|
|
import { Text, View } from 'react-native';
|
2020-02-11 14:01:35 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2022-05-31 16:08:18 +00:00
|
|
|
import FastImage from 'react-native-fast-image';
|
2022-07-13 19:31:58 +00:00
|
|
|
import { FlatList } from 'react-native-gesture-handler';
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2020-10-30 13:59:44 +00:00
|
|
|
import * as List from '../../List';
|
2020-02-11 14:01:35 +00:00
|
|
|
import { textParser } from '../utils';
|
|
|
|
import styles from './styles';
|
2022-03-29 20:06:50 +00:00
|
|
|
import { IItemData } from '.';
|
2022-07-13 19:31:58 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
2022-09-09 18:23:00 +00:00
|
|
|
import { CustomIcon } from '../../CustomIcon';
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IItem {
|
2022-03-29 20:06:50 +00:00
|
|
|
item: IItemData;
|
2023-08-03 19:37:14 +00:00
|
|
|
selected: boolean;
|
2021-09-13 20:41:05 +00:00
|
|
|
onSelect: Function;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IItems {
|
2022-03-29 20:06:50 +00:00
|
|
|
items: IItemData[];
|
2023-08-03 19:37:14 +00:00
|
|
|
selected: IItemData[];
|
2021-09-13 20:41:05 +00:00
|
|
|
onSelect: Function;
|
|
|
|
}
|
|
|
|
|
2022-07-13 19:31:58 +00:00
|
|
|
const keyExtractor = (item: IItemData) => item.value?.name || item.text?.text;
|
2020-02-11 14:01:35 +00:00
|
|
|
|
|
|
|
// RectButton doesn't work on modal (Android)
|
2022-07-13 19:31:58 +00:00
|
|
|
const Item = ({ item, selected, onSelect }: IItem) => {
|
2022-04-08 22:53:48 +00:00
|
|
|
const itemName = item.value?.name || item.text.text.toLowerCase();
|
2022-07-13 19:31:58 +00:00
|
|
|
const { colors } = useTheme();
|
2021-03-18 14:36:50 +00:00
|
|
|
return (
|
2022-09-09 18:23:00 +00:00
|
|
|
<Touchable testID={`multi-select-item-${itemName}`} key={itemName} onPress={() => onSelect(item)}>
|
|
|
|
<View style={styles.item}>
|
|
|
|
<View style={styles.flexZ}>
|
|
|
|
{item.imageUrl ? <FastImage style={styles.itemImage} source={{ uri: item.imageUrl }} /> : null}
|
|
|
|
</View>
|
|
|
|
<View style={styles.flex}>
|
|
|
|
<Text numberOfLines={1} style={{ color: colors.titleText }}>
|
|
|
|
{textParser([item.text])}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<View style={styles.flexZ}>{selected ? <CustomIcon color={colors.tintColor} size={22} name='check' /> : null}</View>
|
|
|
|
</View>
|
2021-03-18 14:36:50 +00:00
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
};
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2022-07-13 19:31:58 +00:00
|
|
|
const Items = ({ items, selected, onSelect }: IItems) => (
|
2020-02-11 14:01:35 +00:00
|
|
|
<FlatList
|
|
|
|
data={items}
|
2022-09-09 18:23:00 +00:00
|
|
|
style={styles.items}
|
|
|
|
contentContainerStyle={styles.itemContent}
|
2020-02-11 14:01:35 +00:00
|
|
|
keyboardShouldPersistTaps='always'
|
2020-10-30 13:59:44 +00:00
|
|
|
ItemSeparatorComponent={List.Separator}
|
2020-02-11 14:01:35 +00:00
|
|
|
keyExtractor={keyExtractor}
|
2023-08-03 19:37:14 +00:00
|
|
|
renderItem={({ item }) => <Item item={item} onSelect={onSelect} selected={!!selected.find(s => s.value === item.value)} />}
|
2020-02-11 14:01:35 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Items;
|