// @flow import * as React from 'react'; import {View} from 'react-native'; import WebView from "react-native-webview"; import {ActivityIndicator, withTheme} from 'react-native-paper'; import HeaderButton from "./HeaderButton"; type Props = { navigation: Object, data: Array<{ url: string, icon: string, name: string, customJS: string }>, headerTitle: string, hasHeaderBackButton: boolean, hasSideMenu: boolean, hasFooter: boolean, } /** * Class defining a webview screen. */ class WebViewScreen extends React.PureComponent { static defaultProps = { hasBackButton: false, hasSideMenu: true, hasFooter: true, }; webviewRef: Object; onRefreshClicked: Function; onWebviewRef: Function; onGoBackWebview: Function; onGoForwardWebview: Function; getRenderLoading: Function; colors: Object; constructor(props) { super(props); this.onRefreshClicked = this.onRefreshClicked.bind(this); this.onWebviewRef = this.onWebviewRef.bind(this); this.onGoBackWebview = this.onGoBackWebview.bind(this); this.onGoForwardWebview = this.onGoForwardWebview.bind(this); this.getRenderLoading = this.getRenderLoading.bind(this); this.colors = props.theme.colors; } componentDidMount() { const rightButton = this.getRefreshButton.bind(this); this.props.navigation.setOptions({ headerRight: rightButton, }); } getHeaderButton(clickAction: Function, icon: string) { return ( ); } getRefreshButton() { return ( {this.getHeaderButton(this.onRefreshClicked, 'refresh')} ); }; onRefreshClicked() { if (this.webviewRef !== null) this.webviewRef.reload(); } onGoBackWebview() { if (this.webviewRef !== null) this.webviewRef.goBack(); } onGoForwardWebview() { if (this.webviewRef !== null) this.webviewRef.goForward(); } onWebviewRef(ref: Object) { this.webviewRef = ref } getRenderLoading() { return ( ); } render() { // console.log("rendering WebViewScreen"); return ( ); } } export default withTheme(WebViewScreen);