application-amicale/screens/PlanexScreen.js

91 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-08-06 19:18:45 +02:00
// @flow
import * as React from 'react';
2019-08-06 19:38:48 +02:00
import {Platform, View} from 'react-native';
import {Spinner} from 'native-base';
2019-08-06 19:18:45 +02:00
import WebView from "react-native-webview";
2019-08-06 19:38:48 +02:00
import Touchable from "react-native-platform-touchable";
import CustomMaterialIcon from "../components/CustomMaterialIcon";
import ThemeManager from "../utils/ThemeManager";
import BaseContainer from "../components/BaseContainer";
2019-08-06 19:18:45 +02:00
type Props = {
navigation: Object,
}
const PLANEX_URL = 'http://planex.insa-toulouse.fr/';
2019-08-06 19:18:45 +02:00
2019-08-08 22:07:49 +02:00
const CUSTOM_CSS_LINK = 'https://srv-falcon.etud.insa-toulouse.fr/~vergnet/appli-amicale/planex/generalCustom.css';
2019-08-06 19:18:45 +02:00
/**
* Class defining the app's planex screen.
* This screen uses a webview to render the planex page
*/
export default class PlanningScreen extends React.Component<Props> {
2019-08-06 19:18:45 +02:00
2019-08-06 19:38:48 +02:00
webview: WebView;
2019-08-08 22:07:49 +02:00
customInjectedJS: string;
constructor() {
super();
this.customInjectedJS =
'document.querySelector(\'head\').innerHTML += \'<meta name="viewport" content="width=device-width, initial-scale=1.0">\';' +
'document.querySelector(\'head\').innerHTML += \'<link rel="stylesheet" href="https://srv-falcon.etud.insa-toulouse.fr/~vergnet/appli-amicale/planex/customMobile.css" type="text/css"/>\';';
if (ThemeManager.getNightMode())
this.customInjectedJS += 'document.querySelector(\'head\').innerHTML += \'<link rel="stylesheet" href="https://srv-falcon.etud.insa-toulouse.fr/~vergnet/appli-amicale/planex/customDark.css" type="text/css"/>\';';
}
2019-08-06 19:38:48 +02:00
getRefreshButton() {
return (
<Touchable
style={{padding: 6}}
onPress={() => this.refreshWebview()}>
<CustomMaterialIcon
color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
icon="refresh"/>
</Touchable>
2019-08-06 19:38:48 +02:00
);
};
refreshWebview() {
this.webview.reload();
}
2019-08-06 19:18:45 +02:00
render() {
const nav = this.props.navigation;
return (
<BaseContainer navigation={nav} headerTitle={'Planex'} headerRightButton={this.getRefreshButton()}>
2019-08-06 19:18:45 +02:00
<WebView
2019-08-06 19:38:48 +02:00
ref={ref => (this.webview = ref)}
2019-08-06 19:18:45 +02:00
source={{uri: PLANEX_URL}}
2019-08-06 19:38:48 +02:00
style={{
width: '100%',
height: '100%',
2019-08-06 19:18:45 +02:00
}}
2019-08-06 19:38:48 +02:00
startInLoadingState={true}
2019-08-08 22:07:49 +02:00
injectedJavaScript={this.customInjectedJS}
javaScriptEnabled={true}
2019-08-06 19:38:48 +02:00
renderLoading={() =>
<View style={{
backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor,
position: 'absolute',
top: 0,
right: 0,
2019-08-06 19:38:48 +02:00
width: '100%',
height: '100%',
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}}>
<Spinner/>
</View>
}
2019-08-06 19:18:45 +02:00
/>
</BaseContainer>
2019-08-06 19:18:45 +02:00
);
}
}