2017-12-02 13:19:58 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2018-05-07 20:41:36 +00:00
|
|
|
import FastImage from 'react-native-fast-image';
|
2018-09-19 14:18:32 +00:00
|
|
|
import { RectButton } from 'react-native-gesture-handler';
|
2018-08-01 19:35:06 +00:00
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
import PhotoModal from './PhotoModal';
|
2018-04-24 19:34:03 +00:00
|
|
|
import Markdown from './Markdown';
|
2018-08-01 19:35:06 +00:00
|
|
|
import styles from './styles';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
export default class extends React.PureComponent {
|
2017-12-02 13:19:58 +00:00
|
|
|
static propTypes = {
|
|
|
|
file: PropTypes.object.isRequired,
|
|
|
|
baseUrl: PropTypes.string.isRequired,
|
2018-07-10 13:40:32 +00:00
|
|
|
user: PropTypes.object.isRequired,
|
2018-09-11 16:32:52 +00:00
|
|
|
customEmojis: PropTypes.oneOfType([
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.object
|
|
|
|
])
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
state = { modalVisible: false };
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
onPressButton() {
|
|
|
|
this.setState({
|
|
|
|
modalVisible: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
getDescription() {
|
2018-09-11 16:32:52 +00:00
|
|
|
const {
|
|
|
|
file, customEmojis, baseUrl, user
|
|
|
|
} = this.props;
|
2018-04-24 19:34:03 +00:00
|
|
|
if (file.description) {
|
2018-09-11 16:32:52 +00:00
|
|
|
return <Markdown msg={file.description} customEmojis={customEmojis} baseUrl={baseUrl} username={user.username} />;
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
isPressed = (state) => {
|
|
|
|
this.setState({ isPressed: state });
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { modalVisible, isPressed } = this.state;
|
2018-03-23 16:49:51 +00:00
|
|
|
const { baseUrl, file, user } = this.props;
|
|
|
|
const img = `${ baseUrl }${ file.image_url }?rc_uid=${ user.id }&rc_token=${ user.token }`;
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2018-12-05 20:52:08 +00:00
|
|
|
if (!img) {
|
2018-09-14 19:39:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
return (
|
2018-04-24 19:34:03 +00:00
|
|
|
[
|
2018-09-19 14:18:32 +00:00
|
|
|
<RectButton
|
2018-04-24 19:34:03 +00:00
|
|
|
key='image'
|
2018-09-19 14:18:32 +00:00
|
|
|
onPress={() => this.onPressButton()}
|
|
|
|
onActiveStateChange={this.isPressed}
|
2018-08-01 19:35:06 +00:00
|
|
|
style={styles.imageContainer}
|
2018-09-19 14:18:32 +00:00
|
|
|
underlayColor='#fff'
|
2017-12-02 13:19:58 +00:00
|
|
|
>
|
2018-05-07 20:41:36 +00:00
|
|
|
<FastImage
|
2018-09-19 14:18:32 +00:00
|
|
|
style={[styles.image, isPressed && { opacity: 0.5 }]}
|
2018-03-23 16:49:51 +00:00
|
|
|
source={{ uri: encodeURI(img) }}
|
2018-09-11 16:32:52 +00:00
|
|
|
resizeMode={FastImage.resizeMode.cover}
|
2018-03-23 16:49:51 +00:00
|
|
|
/>
|
2018-04-24 19:34:03 +00:00
|
|
|
{this.getDescription()}
|
2018-09-19 14:18:32 +00:00
|
|
|
</RectButton>,
|
2017-12-02 13:19:58 +00:00
|
|
|
<PhotoModal
|
2018-04-24 19:34:03 +00:00
|
|
|
key='modal'
|
2018-09-11 16:32:52 +00:00
|
|
|
title={file.title}
|
|
|
|
description={file.description}
|
2018-03-23 16:49:51 +00:00
|
|
|
image={img}
|
2018-09-25 19:28:42 +00:00
|
|
|
isVisible={modalVisible}
|
2017-12-02 13:19:58 +00:00
|
|
|
onClose={() => this.setState({ modalVisible: false })}
|
|
|
|
/>
|
2018-04-24 19:34:03 +00:00
|
|
|
]
|
2017-12-02 13:19:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|