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-04-24 19:34:03 +00:00
|
|
|
import { TouchableOpacity, StyleSheet } from 'react-native';
|
|
|
|
import { connect } from 'react-redux';
|
2017-12-02 13:19:58 +00:00
|
|
|
import PhotoModal from './PhotoModal';
|
2018-04-24 19:34:03 +00:00
|
|
|
import Markdown from './Markdown';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
button: {
|
|
|
|
flex: 1,
|
2018-04-24 19:34:03 +00:00
|
|
|
flexDirection: 'column'
|
2017-12-02 13:19:58 +00:00
|
|
|
},
|
|
|
|
image: {
|
2018-04-24 19:34:03 +00:00
|
|
|
width: 320,
|
2018-05-07 20:41:36 +00:00
|
|
|
height: 200
|
|
|
|
// resizeMode: 'cover'
|
2017-12-02 13:19:58 +00:00
|
|
|
},
|
|
|
|
labelContainer: {
|
2018-04-24 19:34:03 +00:00
|
|
|
alignItems: 'flex-start'
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
@connect(state => ({
|
|
|
|
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
|
|
|
|
}))
|
|
|
|
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,
|
|
|
|
customEmojis: 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
|
|
|
|
|
|
|
getDescription() {
|
2018-04-24 19:34:03 +00:00
|
|
|
const { file, customEmojis } = this.props;
|
|
|
|
if (file.description) {
|
|
|
|
return <Markdown msg={file.description} customEmojis={customEmojis} />;
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onPressButton() {
|
|
|
|
this.setState({
|
|
|
|
modalVisible: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
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 }`;
|
2017-12-02 13:19:58 +00:00
|
|
|
return (
|
2018-04-24 19:34:03 +00:00
|
|
|
[
|
2017-12-02 13:19:58 +00:00
|
|
|
<TouchableOpacity
|
2018-04-24 19:34:03 +00:00
|
|
|
key='image'
|
2017-12-02 13:19:58 +00:00
|
|
|
onPress={() => this._onPressButton()}
|
|
|
|
style={styles.button}
|
|
|
|
>
|
2018-05-07 20:41:36 +00:00
|
|
|
<FastImage
|
2018-03-23 16:49:51 +00:00
|
|
|
style={styles.image}
|
|
|
|
source={{ uri: encodeURI(img) }}
|
|
|
|
/>
|
2018-04-24 19:34:03 +00:00
|
|
|
{this.getDescription()}
|
|
|
|
</TouchableOpacity>,
|
2017-12-02 13:19:58 +00:00
|
|
|
<PhotoModal
|
2018-04-24 19:34:03 +00:00
|
|
|
key='modal'
|
2017-12-02 13:19:58 +00:00
|
|
|
title={this.props.file.title}
|
2018-07-17 19:10:27 +00:00
|
|
|
description={this.props.file.description}
|
2018-03-23 16:49:51 +00:00
|
|
|
image={img}
|
2017-12-02 13:19:58 +00:00
|
|
|
isVisible={this.state.modalVisible}
|
|
|
|
onClose={() => this.setState({ modalVisible: false })}
|
|
|
|
/>
|
2018-04-24 19:34:03 +00:00
|
|
|
]
|
2017-12-02 13:19:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|