2020-02-11 14:01:35 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Text, FlatList } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
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 Separator from '../../Separator';
|
|
|
|
import Check from '../../Check';
|
|
|
|
|
|
|
|
import { textParser } from '../utils';
|
|
|
|
import { themes } from '../../../constants/colors';
|
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
const keyExtractor = item => item.value.toString();
|
|
|
|
|
|
|
|
// RectButton doesn't work on modal (Android)
|
|
|
|
const Item = ({
|
|
|
|
item, selected, onSelect, theme
|
|
|
|
}) => (
|
|
|
|
<Touchable
|
|
|
|
key={item}
|
|
|
|
onPress={() => onSelect(item)}
|
|
|
|
style={[
|
|
|
|
styles.item,
|
|
|
|
{ backgroundColor: themes[theme].backgroundColor }
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<>
|
2020-03-30 19:50:27 +00:00
|
|
|
{item.imageUrl ? <FastImage style={styles.itemImage} source={{ uri: item.imageUrl }} /> : null}
|
2020-02-11 14:01:35 +00:00
|
|
|
<Text style={{ color: themes[theme].titleText }}>{textParser([item.text])}</Text>
|
|
|
|
{selected ? <Check theme={theme} /> : null}
|
|
|
|
</>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
Item.propTypes = {
|
|
|
|
item: PropTypes.object,
|
|
|
|
selected: PropTypes.number,
|
|
|
|
onSelect: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
const Items = ({
|
|
|
|
items, selected, onSelect, theme
|
|
|
|
}) => (
|
|
|
|
<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={() => <Separator theme={theme} />}
|
|
|
|
keyExtractor={keyExtractor}
|
|
|
|
renderItem={({ item }) => <Item item={item} onSelect={onSelect} theme={theme} selected={selected.find(s => s === item.value)} />}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
Items.propTypes = {
|
|
|
|
items: PropTypes.array,
|
|
|
|
selected: PropTypes.array,
|
|
|
|
onSelect: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Items;
|