import React, { useContext } from 'react'; import { StyleProp, TextStyle, View } from 'react-native'; import FastImage from '@rocket.chat/react-native-fast-image'; import { dequal } from 'dequal'; import { createImageProgress } from 'react-native-image-progress'; import * as Progress from 'react-native-progress'; import Touchable from './Touchable'; import Markdown from '../markdown'; import styles from './styles'; import { formatAttachmentUrl } from '../../lib/utils'; import { themes } from '../../constants/colors'; import MessageContext from './Context'; import { TGetCustomEmoji } from '../../definitions/IEmoji'; import { IAttachment } from '../../definitions'; type TMessageButton = { children: JSX.Element; disabled?: boolean; onPress: Function; theme: string; }; type TMessageImage = { img: string; theme: string; }; interface IMessageImage { file: IAttachment; imageUrl?: string; showAttachment?: Function; style?: StyleProp[]; isReply?: boolean; theme: string; getCustomEmoji: TGetCustomEmoji; } const ImageProgress = createImageProgress(FastImage); const Button = React.memo(({ children, onPress, disabled, theme }: TMessageButton) => ( {children} )); export const MessageImage = React.memo(({ img, theme }: TMessageImage) => ( )); const ImageContainer = React.memo( ({ file, imageUrl, showAttachment, getCustomEmoji, style, isReply, theme }: IMessageImage) => { const { baseUrl, user } = useContext(MessageContext); const img = imageUrl || formatAttachmentUrl(file.image_url, user.id, user.token, baseUrl); if (!img) { return null; } const onPress = () => { if (!showAttachment) { return; } return showAttachment(file); }; if (file.description) { return ( ); } return ( ); }, (prevProps, nextProps) => dequal(prevProps.file, nextProps.file) && prevProps.theme === nextProps.theme ); ImageContainer.displayName = 'MessageImageContainer'; MessageImage.displayName = 'MessageImage'; export default ImageContainer;