// @flow import * as React from 'react'; import {Linking, Platform, View} from 'react-native'; import {Spinner} from 'native-base'; import WebView from "react-native-webview"; import Touchable from "react-native-platform-touchable"; import CustomMaterialIcon from "../components/CustomMaterialIcon"; import ThemeManager from "../utils/ThemeManager"; import BaseContainer from "../components/BaseContainer"; type Props = { navigation: Object, url: string, customInjectedJS: string, headerTitle: string, hasHeaderBackButton: boolean, hasSideMenu: boolean, } /** * Class defining a webview screen. */ export default class WebViewScreen extends React.Component { static defaultProps = { customInjectedJS: '', hasBackButton: false, hasSideMenu: true, }; webview: WebView; openWebLink() { Linking.openURL(this.props.url).catch((err) => console.error('Error opening link', err)); } getHeaderButton(clickAction: Function, icon: string) { return ( clickAction()}> ); } getRefreshButton() { return ( {this.getHeaderButton(() => this.openWebLink(), 'web')} {this.getHeaderButton(() => this.refreshWebview(), 'refresh')} ); }; refreshWebview() { this.webview.reload(); } render() { const nav = this.props.navigation; return ( (this.webview = ref)} source={{uri: this.props.url}} style={{ width: '100%', height: '100%', }} startInLoadingState={true} injectedJavaScript={this.props.customInjectedJS} javaScriptEnabled={true} renderLoading={() => } /> ); } }