2019-10-30 14:14:41 +00:00
|
|
|
import React, { useContext, useState } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { TouchableOpacity } from 'react-native';
|
2020-07-17 17:39:06 +00:00
|
|
|
import FastImage from '@rocket.chat/react-native-fast-image';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
|
|
|
import styles from '../styles';
|
|
|
|
import { CustomIcon } from '../../../lib/Icons';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2019-10-30 14:14:41 +00:00
|
|
|
import MessageboxContext from '../Context';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../ActivityIndicator';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const Item = ({ item, theme }) => {
|
2019-10-30 14:14:41 +00:00
|
|
|
const context = useContext(MessageboxContext);
|
|
|
|
const { onPressCommandPreview } = context;
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.commandPreview}
|
|
|
|
onPress={() => onPressCommandPreview(item)}
|
|
|
|
testID={`command-preview-item${ item.id }`}
|
|
|
|
>
|
|
|
|
{item.type === 'image'
|
|
|
|
? (
|
|
|
|
<FastImage
|
|
|
|
style={styles.commandPreviewImage}
|
|
|
|
source={{ uri: item.value }}
|
|
|
|
resizeMode={FastImage.resizeMode.cover}
|
|
|
|
onLoadStart={() => setLoading(true)}
|
|
|
|
onLoad={() => setLoading(false)}
|
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
{ loading ? <ActivityIndicator theme={theme} /> : null }
|
2019-10-30 14:14:41 +00:00
|
|
|
</FastImage>
|
|
|
|
)
|
2020-07-27 19:53:33 +00:00
|
|
|
: <CustomIcon name='attach' size={36} color={themes[theme].actionTintColor} />
|
2019-10-30 14:14:41 +00:00
|
|
|
}
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Item.propTypes = {
|
2019-12-04 16:39:53 +00:00
|
|
|
item: PropTypes.object,
|
|
|
|
theme: PropTypes.string
|
2019-10-30 14:14:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Item;
|