2022-05-31 16:08:18 +00:00
|
|
|
import FastImage from '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
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../../CustomIcon';
|
2022-03-31 22:39:24 +00:00
|
|
|
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)}
|
2022-08-08 21:02:08 +00:00
|
|
|
testID={`command-preview-item${item.id}`}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
{item.type === 'image' ? (
|
|
|
|
<FastImage
|
|
|
|
style={styles.commandPreviewImage}
|
|
|
|
source={{ uri: item.value }}
|
|
|
|
resizeMode={FastImage.resizeMode.cover}
|
|
|
|
onLoadStart={() => setLoading(true)}
|
2022-08-08 21:02:08 +00:00
|
|
|
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;
|