vn-verdnaturachat/app/containers/UIKit/MultiSelect/Items.tsx

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-02-11 14:01:35 +00:00
import React from 'react';
import { FlatList, Text } from 'react-native';
2020-02-11 14:01:35 +00:00
import Touchable from 'react-native-platform-touchable';
import FastImage from '@rocket.chat/react-native-fast-image';
2020-02-11 14:01:35 +00:00
import Check from '../../Check';
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';
interface IItem {
item: {
value: { name: string };
text: { text: string };
imageUrl: string;
};
selected: any;
onSelect: Function;
theme: string;
}
interface IItems {
items: [];
selected: [];
onSelect: Function;
theme: string;
}
const keyExtractor = (item: any) => item.value.toString();
2020-02-11 14:01:35 +00:00
// RectButton doesn't work on modal (Android)
const Item = ({ item, selected, onSelect, theme }: IItem) => {
const itemName = item.value.name || item.text.text.toLowerCase();
return (
<Touchable
testID={`multi-select-item-${itemName}`}
key={item}
onPress={() => onSelect(item)}
style={[styles.item, { backgroundColor: themes[theme].backgroundColor }]}>
<>
{item.imageUrl ? <FastImage style={styles.itemImage} source={{ uri: item.imageUrl }} /> : null}
<Text style={{ color: themes[theme].titleText }}>{textParser([item.text])}</Text>
{selected ? <Check theme={theme} /> : null}
</>
</Touchable>
);
};
2020-02-11 14:01:35 +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'
ItemSeparatorComponent={List.Separator}
2020-02-11 14:01:35 +00:00
keyExtractor={keyExtractor}
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;