application-amicale/screens/Planning/PlanningDisplayScreen.js

96 lines
3.1 KiB
JavaScript
Raw Normal View History

// @flow
import * as React from 'react';
import {ScrollView, View} from 'react-native';
import HTML from "react-native-render-html";
import {Linking} from "expo";
2020-03-30 15:28:08 +02:00
import {getDateOnlyString, getFormattedEventTime} from '../../utils/Planning';
import {Card, withTheme} from 'react-native-paper';
2020-03-30 15:28:08 +02:00
import DateManager from "../../managers/DateManager";
import ImageModal from 'react-native-image-modal';
type Props = {
navigation: Object,
2020-03-06 09:12:56 +01:00
route: Object
};
2020-04-02 15:33:12 +02:00
type State = {
imageModalVisible: boolean,
};
2020-02-11 01:05:24 +01:00
function openWebLink(event, link) {
Linking.openURL(link).catch((err) => console.error('Error opening link', err));
}
/**
2020-03-29 15:59:25 +02:00
* Class defining a planning event information page.
*/
2020-04-02 15:33:12 +02:00
class PlanningDisplayScreen extends React.Component<Props, State> {
2020-03-06 09:12:56 +01:00
displayData = this.props.route.params['data'];
colors: Object;
2020-04-02 15:33:12 +02:00
state = {
imageModalVisible: false,
};
constructor(props) {
super(props);
this.colors = props.theme.colors;
}
2020-04-02 15:33:12 +02:00
showImageModal = () => {
this.setState({imageModalVisible: true});
};
hideImageModal = () => {
this.setState({imageModalVisible: false});
};
render() {
2020-02-11 01:05:24 +01:00
// console.log("rendering planningDisplayScreen");
2020-03-30 15:28:08 +02:00
let subtitle = getFormattedEventTime(
2020-03-22 17:02:00 +01:00
this.displayData["date_begin"], this.displayData["date_end"]);
2020-03-30 15:28:08 +02:00
let dateString = getDateOnlyString(this.displayData["date_begin"]);
2020-03-22 17:02:00 +01:00
if (dateString !== null)
subtitle += ' | ' + DateManager.getInstance().getTranslatedDate(dateString);
return (
<ScrollView style={{paddingLeft: 5, paddingRight: 5}}>
2020-03-08 12:05:22 +01:00
<Card.Title
title={this.displayData.title}
2020-03-22 17:02:00 +01:00
subtitle={subtitle}
2020-03-08 12:05:22 +01:00
/>
{this.displayData.logo !== null ?
<View style={{marginLeft: 'auto', marginRight: 'auto'}}>
<ImageModal
resizeMode="contain"
imageBackgroundColor={this.colors.background}
style={{
width: 300,
height: 300,
}}
source={{
uri: this.displayData.logo,
}}
/></View>
: <View/>}
{this.displayData.description !== null ?
// Surround description with div to allow text styling if the description is not html
2020-03-08 12:05:22 +01:00
<Card.Content>
<HTML html={"<div>" + this.displayData.description + "</div>"}
tagsStyles={{
p: {color: this.colors.text,},
div: {color: this.colors.text}
2020-03-08 12:05:22 +01:00
}}
onLinkPress={openWebLink}/>
</Card.Content>
: <View/>}
</ScrollView>
);
}
}
export default withTheme(PlanningDisplayScreen);