2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View } from 'react-native';
|
2017-12-02 13:19:58 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-05-07 20:41:36 +00:00
|
|
|
import FastImage from 'react-native-fast-image';
|
2018-12-21 10:55:35 +00:00
|
|
|
import equal from 'deep-equal';
|
2019-04-08 12:35:28 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2018-08-01 19:35:06 +00:00
|
|
|
|
2019-09-03 19:27:57 +00:00
|
|
|
import Markdown from '../markdown';
|
2018-08-01 19:35:06 +00:00
|
|
|
import styles from './styles';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { formatAttachmentUrl } from '../../lib/utils';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const Button = React.memo(({ children, onPress }) => (
|
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
|
|
|
style={styles.imageContainer}
|
|
|
|
background={Touchable.Ripple('#fff')}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Touchable>
|
|
|
|
));
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const Image = React.memo(({ img }) => (
|
|
|
|
<FastImage
|
|
|
|
style={styles.image}
|
|
|
|
source={{ uri: encodeURI(img) }}
|
|
|
|
resizeMode={FastImage.resizeMode.cover}
|
|
|
|
/>
|
|
|
|
));
|
2018-12-21 10:55:35 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const ImageContainer = React.memo(({
|
|
|
|
file, baseUrl, user, useMarkdown, onOpenFileModal, getCustomEmoji
|
|
|
|
}) => {
|
|
|
|
const img = formatAttachmentUrl(file.image_url, user.id, user.token, baseUrl);
|
|
|
|
if (!img) {
|
|
|
|
return null;
|
2018-12-21 10:55:35 +00:00
|
|
|
}
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const onPress = () => onOpenFileModal(file);
|
2018-09-19 14:18:32 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
if (file.description) {
|
|
|
|
return (
|
|
|
|
<Button onPress={onPress}>
|
|
|
|
<View>
|
|
|
|
<Image img={img} />
|
|
|
|
<Markdown msg={file.description} baseUrl={baseUrl} username={user.username} getCustomEmoji={getCustomEmoji} useMarkdown={useMarkdown} />
|
|
|
|
</View>
|
|
|
|
</Button>
|
|
|
|
);
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<Button onPress={onPress}>
|
|
|
|
<Image img={img} />
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}, (prevProps, nextProps) => equal(prevProps.file, nextProps.file));
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
ImageContainer.propTypes = {
|
|
|
|
file: PropTypes.object,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: PropTypes.object,
|
|
|
|
useMarkdown: PropTypes.bool,
|
|
|
|
onOpenFileModal: PropTypes.func,
|
|
|
|
getCustomEmoji: PropTypes.func
|
|
|
|
};
|
|
|
|
ImageContainer.displayName = 'MessageImageContainer';
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
Image.propTypes = {
|
|
|
|
img: PropTypes.string
|
|
|
|
};
|
|
|
|
ImageContainer.displayName = 'MessageImage';
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
Button.propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
onPress: PropTypes.func
|
|
|
|
};
|
|
|
|
ImageContainer.displayName = 'MessageButton';
|
|
|
|
|
|
|
|
export default ImageContainer;
|