CommonWebView.js 1.84 KB
import React from 'react'
import {StatusBar, StyleSheet, View, WebView} from 'react-native'
import {getFooterBottom} from "../utils/utils";
import {width} from "../utils/getSize";
import LoadingView from "../components/LoadingView";

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff'
    },
    tabIcon: {
        height: 20,
        width: 20,
    },
    text: {
        fontSize: 20
    }
})

export default class CommonWebView extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            loading: true
        };
        this.url = this.props.navigation.state.params.url
    }

    componentWillMount() {
        //设置头部
        this.props.navigation.setParams({
            isBack: true,
            title: ''
        });
    }

    render() {
        return (
            <View style={styles.container}>
                <StatusBar barStyle={'default'} networkActivityIndicatorVisible/>
                <WebView
                    originWhitelist={['*']}
                    bounces={false}
                    style={{flex: 1, backgroundColor: '#fff'}}
                    ref="webView"
                    source={{uri: this.url}}
                    mixedContentMode={'always'}
                    //onMessage={toNext}
                    injectedJavaScript={''}
                    javaScriptEnabled={true}
                    domStorageEnabled={true}
                    useWebKit={true}
                    onLoadEnd={v => {
                        this.setState({
                            loading: false
                        })
                    }}
                />
                <View style={{width: width, height: getFooterBottom(), backgroundColor: '#fff'}}/>
                {this.state.loading && <LoadingView/>}
            </View>
        )
    }
}