2020-02-11 14:01:35 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { FlatList, Text } from 'react-native';
|
2020-02-11 14:01:35 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2020-07-17 17:39:06 +00:00
|
|
|
import FastImage from '@rocket.chat/react-native-fast-image';
|
2020-02-11 14:01:35 +00:00
|
|
|
|
|
|
|
import Check from '../../Check';
|
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 { themes } from '../../../constants/colors';
|
|
|
|
import styles from './styles';
|
2022-03-29 20:06:50 +00:00
|
|
|
import { IItemData } from '.';
|
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;
|
|
|
|
selected?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
onSelect: Function;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IItems {
|
2022-03-29 20:06:50 +00:00
|
|
|
items: IItemData[];
|
|
|
|
selected: string[];
|
2021-09-13 20:41:05 +00:00
|
|
|
onSelect: Function;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
2022-03-29 20:06:50 +00:00
|
|
|
const keyExtractor = (item: IItemData) => item.value.toString();
|
2020-02-11 14:01:35 +00:00
|
|
|
|
|
|
|
// RectButton doesn't work on modal (Android)
|
2021-09-13 20:41:05 +00:00
|
|
|
const Item = ({ item, selected, onSelect, theme }: IItem) => {
|
2022-03-29 20:06:50 +00:00
|
|
|
const itemName = item.value || item.text.text.toLowerCase();
|
2021-03-18 14:36:50 +00:00
|
|
|
return (
|
|
|
|
<Touchable
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={`multi-select-item-${itemName}`}
|
2022-03-29 20:06:50 +00:00
|
|
|
key={itemName}
|
2021-03-18 14:36:50 +00:00
|
|
|
onPress={() => onSelect(item)}
|
2021-09-13 20:41:05 +00:00
|
|
|
style={[styles.item, { backgroundColor: themes[theme].backgroundColor }]}>
|
2021-03-18 14:36:50 +00:00
|
|
|
<>
|
|
|
|
{item.imageUrl ? <FastImage style={styles.itemImage} source={{ uri: item.imageUrl }} /> : null}
|
|
|
|
<Text style={{ color: themes[theme].titleText }}>{textParser([item.text])}</Text>
|
2022-03-22 13:53:09 +00:00
|
|
|
{selected ? <Check /> : null}
|
2021-03-18 14:36:50 +00:00
|
|
|
</>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
};
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Items = ({ items, selected, onSelect, theme }: IItems) => (
|
2020-02-11 14:01:35 +00:00
|
|
|
<FlatList
|
|
|
|
data={items}
|
|
|
|
style={[styles.items, { backgroundColor: themes[theme].backgroundColor }]}
|
2020-02-12 17:21:11 +00:00
|
|
|
contentContainerStyle={[styles.itemContent, { backgroundColor: themes[theme].backgroundColor }]}
|
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}
|
2021-09-13 20:41:05 +00:00
|
|
|
renderItem={({ item }) => (
|
|
|
|
<Item item={item} onSelect={onSelect} theme={theme} selected={selected.find(s => s === item.value)} />
|
|
|
|
)}
|
2020-02-11 14:01:35 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Items;
|