2022-03-31 22:39:24 +00:00
|
|
|
import FastImage from '@rocket.chat/react-native-fast-image';
|
2019-10-30 14:14:41 +00:00
|
|
|
import React, { useContext, useState } from 'react';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { TouchableOpacity } from 'react-native';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2022-03-31 22:39:24 +00:00
|
|
|
import { CustomIcon } from '../../../lib/Icons';
|
|
|
|
import { useTheme } from '../../../theme';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../ActivityIndicator';
|
2022-03-31 22:39:24 +00:00
|
|
|
import MessageboxContext from '../Context';
|
|
|
|
import styles from '../styles';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IMessageBoxCommandsPreviewItem {
|
|
|
|
item: {
|
|
|
|
type: string;
|
|
|
|
id: string;
|
|
|
|
value: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-31 22:39:24 +00:00
|
|
|
const Item = ({ item }: IMessageBoxCommandsPreviewItem) => {
|
2019-10-30 14:14:41 +00:00
|
|
|
const context = useContext(MessageboxContext);
|
|
|
|
const { onPressCommandPreview } = context;
|
|
|
|
const [loading, setLoading] = useState(true);
|
2022-03-31 22:39:24 +00:00
|
|
|
const { theme } = useTheme();
|
2019-10-30 14:14:41 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.commandPreview}
|
|
|
|
onPress={() => onPressCommandPreview(item)}
|
2021-09-13 20:41:05 +00:00
|
|
|
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)}>
|
2022-03-18 02:37:10 +00:00
|
|
|
{loading ? <ActivityIndicator /> : null}
|
2021-09-13 20:41:05 +00:00
|
|
|
</FastImage>
|
|
|
|
) : (
|
2022-03-31 22:39:24 +00:00
|
|
|
<CustomIcon name='attach' size={36} color={themes[theme].actionTintColor} />
|
2021-09-13 20:41:05 +00:00
|
|
|
)}
|
2019-10-30 14:14:41 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Item;
|