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';
|
2020-01-29 20:20:36 +00:00
|
|
|
import { createImageProgress } from 'react-native-image-progress';
|
|
|
|
import * as Progress from 'react-native-progress';
|
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';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { withSplit } from '../../split';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import sharedStyles from '../../views/Styles';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2020-01-29 20:20:36 +00:00
|
|
|
const ImageProgress = createImageProgress(FastImage);
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
const Button = React.memo(({
|
|
|
|
children, onPress, split, theme
|
|
|
|
}) => (
|
2019-05-20 20:43:50 +00:00
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.imageContainer, split && sharedStyles.tabletContent]}
|
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
2019-05-20 20:43:50 +00:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Touchable>
|
|
|
|
));
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2020-02-19 19:43:47 +00:00
|
|
|
export const MessageImage = React.memo(({ img, theme }) => (
|
2020-01-29 20:20:36 +00:00
|
|
|
<ImageProgress
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.image, { borderColor: themes[theme].borderColor }]}
|
2019-05-20 20:43:50 +00:00
|
|
|
source={{ uri: encodeURI(img) }}
|
|
|
|
resizeMode={FastImage.resizeMode.cover}
|
2020-01-29 20:20:36 +00:00
|
|
|
indicator={Progress.Pie}
|
|
|
|
indicatorProps={{
|
|
|
|
color: themes[theme].actionTintColor
|
|
|
|
}}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
));
|
2018-12-21 10:55:35 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const ImageContainer = React.memo(({
|
2020-03-18 21:26:17 +00:00
|
|
|
file, imageUrl, baseUrl, user, showAttachment, getCustomEmoji, split, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2020-02-19 19:43:47 +00:00
|
|
|
const img = imageUrl || formatAttachmentUrl(file.image_url, user.id, user.token, baseUrl);
|
2019-05-20 20:43:50 +00:00
|
|
|
if (!img) {
|
|
|
|
return null;
|
2018-12-21 10:55:35 +00:00
|
|
|
}
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2020-01-29 20:20:36 +00:00
|
|
|
const onPress = () => showAttachment(file);
|
2018-09-19 14:18:32 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
if (file.description) {
|
|
|
|
return (
|
2019-12-11 23:01:12 +00:00
|
|
|
<Button split={split} theme={theme} onPress={onPress}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<View>
|
2020-02-19 19:43:47 +00:00
|
|
|
<MessageImage img={img} theme={theme} />
|
2020-03-18 21:26:17 +00:00
|
|
|
<Markdown msg={file.description} baseUrl={baseUrl} username={user.username} getCustomEmoji={getCustomEmoji} theme={theme} />
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
</Button>
|
|
|
|
);
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2019-12-11 23:01:12 +00:00
|
|
|
<Button split={split} theme={theme} onPress={onPress}>
|
2020-02-19 19:43:47 +00:00
|
|
|
<MessageImage img={img} theme={theme} />
|
2019-05-20 20:43:50 +00:00
|
|
|
</Button>
|
|
|
|
);
|
2019-12-11 23:01:12 +00:00
|
|
|
}, (prevProps, nextProps) => equal(prevProps.file, nextProps.file) && prevProps.split === nextProps.split && prevProps.theme === nextProps.theme);
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
ImageContainer.propTypes = {
|
|
|
|
file: PropTypes.object,
|
2020-02-19 19:43:47 +00:00
|
|
|
imageUrl: PropTypes.string,
|
2019-05-20 20:43:50 +00:00
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: PropTypes.object,
|
2020-01-29 20:20:36 +00:00
|
|
|
showAttachment: PropTypes.func,
|
2019-12-11 23:01:12 +00:00
|
|
|
theme: PropTypes.string,
|
|
|
|
getCustomEmoji: PropTypes.func,
|
|
|
|
split: PropTypes.bool
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
ImageContainer.displayName = 'MessageImageContainer';
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2020-02-19 19:43:47 +00:00
|
|
|
MessageImage.propTypes = {
|
2019-12-11 23:01:12 +00:00
|
|
|
img: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
ImageContainer.displayName = 'MessageImage';
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
Button.propTypes = {
|
|
|
|
children: PropTypes.node,
|
2019-12-11 23:01:12 +00:00
|
|
|
onPress: PropTypes.func,
|
|
|
|
theme: PropTypes.string,
|
|
|
|
split: PropTypes.bool
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
ImageContainer.displayName = 'MessageButton';
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
export default withSplit(ImageContainer);
|