Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SelfMenuScreen.js 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // @flow
  2. import * as React from 'react';
  3. import {Platform, View} from 'react-native';
  4. import {Container, Spinner} from 'native-base';
  5. import WebView from "react-native-webview";
  6. import Touchable from "react-native-platform-touchable";
  7. import CustomMaterialIcon from "../components/CustomMaterialIcon";
  8. import ThemeManager from "../utils/ThemeManager";
  9. import CustomHeader from "../components/CustomHeader";
  10. import i18n from "i18n-js";
  11. type Props = {
  12. navigation: Object,
  13. }
  14. const RU_URL = 'http://m.insa-toulouse.fr/ru.html';
  15. const CUSTOM_CSS_GENERAL = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/custom_css/RU/customGeneral.css';
  16. const CUSTOM_CSS_LIGHT = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/custom_css/RU/customLight.css';
  17. /**
  18. * Class defining the app's planex screen.
  19. * This screen uses a webview to render the planex page
  20. */
  21. export default class SelfMenuScreen extends React.Component<Props> {
  22. webview: WebView;
  23. customInjectedJS: string;
  24. constructor() {
  25. super();
  26. this.customInjectedJS =
  27. 'document.querySelector(\'head\').innerHTML += \'<meta name="viewport" content="width=device-width, initial-scale=1.0">\';' +
  28. 'document.querySelector(\'head\').innerHTML += \'<link rel="stylesheet" href="' + CUSTOM_CSS_GENERAL + '" type="text/css"/>\';';
  29. if (!ThemeManager.getNightMode())
  30. this.customInjectedJS += 'document.querySelector(\'head\').innerHTML += \'<link rel="stylesheet" href="' + CUSTOM_CSS_LIGHT + '" type="text/css"/>\';';
  31. }
  32. getRefreshButton() {
  33. return (
  34. <Touchable
  35. style={{padding: 6}}
  36. onPress={() => this.refreshWebview()}>
  37. <CustomMaterialIcon
  38. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  39. icon="refresh"/>
  40. </Touchable>
  41. );
  42. };
  43. refreshWebview() {
  44. this.webview.reload();
  45. }
  46. render() {
  47. const nav = this.props.navigation;
  48. return (
  49. <Container>
  50. <CustomHeader navigation={nav} title={i18n.t('screens.menuSelf')} hasBackButton={true}
  51. rightButton={this.getRefreshButton()}/>
  52. <WebView
  53. ref={ref => (this.webview = ref)}
  54. source={{uri: RU_URL}}
  55. style={{
  56. width: '100%',
  57. height: '100%',
  58. }}
  59. startInLoadingState={true}
  60. injectedJavaScript={this.customInjectedJS}
  61. javaScriptEnabled={true}
  62. renderLoading={() =>
  63. <View style={{
  64. backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor,
  65. position: 'absolute',
  66. top: 0,
  67. right: 0,
  68. width: '100%',
  69. height: '100%',
  70. flex: 1,
  71. alignItems: 'center',
  72. justifyContent: 'center'
  73. }}>
  74. <Spinner/>
  75. </View>
  76. }
  77. />
  78. </Container>
  79. );
  80. }
  81. }