// @flow import * as React from 'react'; import {StackNavigationProp} from "@react-navigation/stack"; import WebViewScreen from "../../components/Screens/WebViewScreen"; import AvailableWebsites from "../../constants/AvailableWebsites"; import BasicLoadingScreen from "../../components/Screens/BasicLoadingScreen"; type Props = { navigation: StackNavigationProp, route: { params: { host: string, path: string | null, title: string } }, } class WebsiteScreen extends React.Component { fullUrl: string; injectedJS: { [key: string]: string }; customPaddingFunctions: {[key: string]: (padding: string) => string} host: string; constructor(props: Props) { super(props); this.props.navigation.addListener('focus', this.onScreenFocus); this.injectedJS = {}; this.customPaddingFunctions = {}; this.injectedJS[AvailableWebsites.websites.AVAILABLE_ROOMS] = 'document.querySelector(\'head\').innerHTML += \'\';' + 'document.querySelector(\'head\').innerHTML += \'\'; true;'; this.injectedJS[AvailableWebsites.websites.BIB] = 'document.querySelector(\'head\').innerHTML += \'\';' + 'document.querySelector(\'head\').innerHTML += \'\';' + 'if ($(".hero-unit-form").length > 0 && $("#customBackButton").length === 0)' + '$(".hero-unit-form").append("' + '
' + '' + '' + '' + '
");true;'; this.customPaddingFunctions[AvailableWebsites.websites.BLUEMIND] = (padding: string) => { return ( "$('head').append('');" + "$('.minwidth').css('top', " + padding + ");" + "$('#mailview-bottom').css('min-height', 500);" ); }; this.customPaddingFunctions[AvailableWebsites.websites.WIKETUD] = (padding: string) => { return ( "$('#p-logo-text').css('top', 10 + " + padding + ");" + "$('#site-navigation h2').css('top', 10 + " + padding + ");" + "$('#site-tools h2').css('top', 10 + " + padding + ");" + "$('#user-tools h2').css('top', 10 + " + padding + ");" ); } } onScreenFocus = () => { this.handleNavigationParams(); }; /** * */ handleNavigationParams() { if (this.props.route.params != null) { this.host = this.props.route.params.host; let path = this.props.route.params.path; const title = this.props.route.params.title; if (this.host != null && path != null) { path = path.replace(this.host, ""); this.fullUrl = this.host + path; }else this.fullUrl = this.host; if (title != null) this.props.navigation.setOptions({title: title}); } } render() { let injectedJavascript = ""; let customPadding = null; if (this.host != null && this.injectedJS[this.host] != null) injectedJavascript = this.injectedJS[this.host]; if (this.host != null && this.customPaddingFunctions[this.host] != null) customPadding = this.customPaddingFunctions[this.host]; if (this.fullUrl != null) { return ( ); } else { return ( ); } } } export default WebsiteScreen;