2017-08-15 19:28:46 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import Meteor from 'react-native-meteor';
|
2017-08-18 21:30:16 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-08-15 19:28:46 +00:00
|
|
|
import { CachedImage } from 'react-native-img-cache';
|
|
|
|
import { Text, TouchableOpacity } from 'react-native';
|
|
|
|
import { Navigation } from 'react-native-navigation';
|
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
CardImage,
|
|
|
|
// CardTitle,
|
|
|
|
CardContent
|
|
|
|
// CardAction
|
|
|
|
} from 'react-native-card-view';
|
|
|
|
import RocketChat from '../../lib/rocketchat';
|
|
|
|
|
|
|
|
const close = () => Navigation.dismissModal({
|
|
|
|
animationType: 'slide-down'
|
|
|
|
});
|
|
|
|
|
|
|
|
const CustomButton = ({ text }) => (
|
|
|
|
<TouchableOpacity onPress={close}>
|
|
|
|
<Text style={{ color: 'blue' }}>{text}</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
|
2017-08-18 14:50:20 +00:00
|
|
|
CustomButton.propTypes = {
|
|
|
|
text: PropTypes.string
|
|
|
|
};
|
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
Navigation.registerComponent('CustomButton', () => CustomButton);
|
2017-08-18 14:50:20 +00:00
|
|
|
|
2017-08-18 21:30:16 +00:00
|
|
|
@connect(state => ({
|
|
|
|
base: state.settings.Site_Url,
|
|
|
|
canShowList: state.login.token.length || state.login.user.token
|
|
|
|
}))
|
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
export default class Cards extends React.PureComponent {
|
|
|
|
static propTypes = {
|
2017-08-22 01:24:41 +00:00
|
|
|
data: PropTypes.object.isRequired,
|
|
|
|
base: PropTypes.string
|
2017-08-15 19:28:46 +00:00
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
const user = Meteor.user();
|
|
|
|
this.state = {};
|
|
|
|
RocketChat.getUserToken().then((token) => {
|
2017-08-18 21:30:16 +00:00
|
|
|
this.setState({ img: `${ this.props.base }${ this.props.data.image_url }?rc_uid=${ user._id }&rc_token=${ token }` });
|
2017-08-15 19:28:46 +00:00
|
|
|
});
|
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
|
|
|
getImage() {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={() => this._onPressButton()}>
|
|
|
|
<Card>
|
|
|
|
<CardImage style={{ width: 256, height: 256 }}>
|
|
|
|
<CachedImage
|
|
|
|
style={{ width: 256, height: 256 }}
|
|
|
|
source={{ uri: encodeURI(this.state.img) }}
|
|
|
|
/>
|
|
|
|
</CardImage>
|
|
|
|
<CardContent>
|
|
|
|
<Text style={[{ fontSize: 12, alignSelf: 'center', fontStyle: 'italic' }]}>{this.props.data.title}</Text>
|
|
|
|
<Text style={{ alignSelf: 'center', fontWeight: 'bold' }}>{this.props.data.description}</Text>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getOther() {
|
|
|
|
return (
|
|
|
|
<Text style={[{ fontSize: 12, alignSelf: 'center', fontStyle: 'italic' }]}>{this.props.data.title}</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
_onPressButton() {
|
|
|
|
Navigation.showModal({
|
|
|
|
screen: 'Photo',
|
|
|
|
title: this.props.data.title, // title of the screen as appears in the nav bar (optional)
|
|
|
|
passProps: { image: this.state.img },
|
|
|
|
// navigatorStyle: {}, // override the navigator style for the screen, see "Styling the navigator" below (optional)
|
|
|
|
navigatorButtons: {
|
|
|
|
leftButtons: [{
|
|
|
|
id: 'custom-button',
|
|
|
|
component: 'CustomButton',
|
|
|
|
passProps: {
|
|
|
|
text: 'close'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}, // override the nav buttons for the screen, see "Adding buttons to the navigator" below (optional)
|
|
|
|
animationType: 'slide-up' // 'none' / 'slide-up' , appear animation for the modal (optional, default 'slide-up')
|
|
|
|
});
|
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
render() {
|
2017-09-01 19:17:53 +00:00
|
|
|
return this.state.img ? this.getImage() : this.getOther();
|
2017-08-15 19:28:46 +00:00
|
|
|
}
|
|
|
|
}
|