// @flow import * as React from 'react'; import {Platform, View} from 'react-native'; import {Container, Spinner, Tab, TabHeading, Tabs, Text} from 'native-base'; import WebView from "react-native-webview"; import Touchable from "react-native-platform-touchable"; import {MaterialCommunityIcons} from "@expo/vector-icons"; import ThemeManager from "../utils/ThemeManager"; 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. */ export default class WebViewScreen extends React.Component { static defaultProps = { hasBackButton: false, hasSideMenu: true, hasFooter: true, }; webviewArray: Array = []; onRefreshClicked: Function; onWebviewRef: Function; onGoBackWebview: Function; onGoForwardWebview: Function; onOpenWebLink: Function; constructor() { super(); 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.onOpenWebLink = this.onOpenWebLink.bind(this); } 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() { for (let view of this.webviewArray) { if (view !== null) view.reload(); } } onGoBackWebview() { for (let view of this.webviewArray) { if (view !== null) view.goBack(); } } onGoForwardWebview() { for (let view of this.webviewArray) { if (view !== null) view.goForward(); } } onOpenWebLink() { this.openWebLink(this.props.data[0]['url']) } onWebviewRef(ref: WebView) { this.webviewArray.push(ref) } getRenderLoading() { return ( ); } getWebview(obj: Object) { return ( ); } getTabbedWebview() { let tabbedView = []; for (let i = 0; i < this.props.data.length; i++) { tabbedView.push( {this.props.data[i]['name']} } key={this.props.data[i]['url']} style={{backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor}}> {this.getWebview(this.props.data[i])} ); } return tabbedView; } render() { // console.log("rendering WebViewScreen"); const nav = this.props.navigation; this.webviewArray = []; return ( {this.props.data.length === 1 ? this.getWebview(this.props.data[0]) : {this.getTabbedWebview()} } ); } }