vn-verdnaturachat/app/containers/MessageBox/CommandsPreview/Item.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

import React, { useContext, useState } from 'react';
import PropTypes from 'prop-types';
2019-12-04 16:39:53 +00:00
import { TouchableOpacity } from 'react-native';
import FastImage from '@rocket.chat/react-native-fast-image';
import styles from '../styles';
import { CustomIcon } from '../../../lib/Icons';
2019-12-04 16:39:53 +00:00
import { themes } from '../../../constants/colors';
import MessageboxContext from '../Context';
2019-12-04 16:39:53 +00:00
import ActivityIndicator from '../../ActivityIndicator';
2019-12-04 16:39:53 +00:00
const Item = ({ item, theme }) => {
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 }
</FastImage>
)
2020-07-27 19:53:33 +00:00
: <CustomIcon name='attach' size={36} color={themes[theme].actionTintColor} />
}
</TouchableOpacity>
);
};
Item.propTypes = {
2019-12-04 16:39:53 +00:00
item: PropTypes.object,
theme: PropTypes.string
};
export default Item;