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 { themes } from '../../lib/constants'; import MessageContext from './Context'; import { TGetCustomEmoji } from '../../definitions/IEmoji'; import { IAttachment } from '../../definitions'; import { TSupportedThemes, useTheme } from '../../theme'; import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl'; interface IMessageButton { children: React.ReactElement; disabled?: boolean; onPress: () => void; theme: TSupportedThemes; } interface IMessageImage { file: IAttachment; imageUrl?: string; showAttachment?: (file: IAttachment) => void; style?: StyleProp[]; isReply?: boolean; getCustomEmoji?: TGetCustomEmoji; } const ImageProgress = createImageProgress(FastImage); const Button = React.memo(({ children, onPress, disabled, theme }: IMessageButton) => ( {children} )); export const MessageImage = React.memo(({ imgUri, theme }: { imgUri: string; theme: TSupportedThemes }) => ( )); const ImageContainer = React.memo( ({ file, imageUrl, showAttachment, getCustomEmoji, style, isReply }: IMessageImage) => { const { theme } = useTheme(); 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) ); ImageContainer.displayName = 'MessageImageContainer'; MessageImage.displayName = 'MessageImage'; export default ImageContainer;