react-native webview安卓下的显示问题

最近用react-native开发APP的时候遇到了一个奇葩的问题
APP需要用到webview,然后安装了一个react-native-webview插件,显示一个url,在ios下没有问题
在安卓下就有问题了,在安卓下有一个页面用到了webview 可以正常显示出来 但是在其它需要用到webview的页面,死活显示不出来,都是这个webview 不知道为什么会这样
这个页面里可以正常显示
import React, { Component } from 'react';
import { WebView }from 'react-native-webview';
import NavigationBar from '../commons/NavigationBar'
import viewsUtil from "../utils/viewsUtil";
import NavigationUtil from "../navigators/NavigationUtils";
import BackPressUtil from "../utils/BackPressUtil";
import SafeAreaViewPlus from '../commons/SafeaAreaViewPlus'

export default class WebViewPage extends Component {

constructor(props) {
    super(props);
    const { title, url, theme } = this.props.navigation.state.params;
    this.theme = theme
    this.state = {
        title,
        url,
        canGoBack: false,
    };
    this.backPress = new BackPressUtil({backPress: () => this.onBackPress()});
}

componentDidMount() {
    this.backPress.componentDidMount();
}

componentWillUnmount() {
    this.backPress.componentWillUnmount();
}

onBackPress() {
    if (this.state.canGoBack) {
        this.webView.goBack();
    } else {
        NavigationUtil.goBack(this.props.navigation);
    }
    return true;
}

onNavigationStateChange(navState) {
    this.setState({
        canGoBack: navState.canGoBack,
        url: navState.url,
    })
}

render() {
    let navigationBar = <NavigationBar
        title={this.state.title}
        style={this.theme.styles.navBar}
        leftButton={viewsUtil.getLeftBackButton(() => this.onBackPress())}
    />;

    return (
        <SafeAreaViewPlus
            topColor={this.theme.themeColor}
        >
            {navigationBar}
            <WebView
                ref={webView => this.webView = webView}
                startInLoadingState={true}
                onNavigationStateChange={e => this.onNavigationStateChange(e)}
                source={{uri: this.state.url}}
            />
        </SafeAreaViewPlus>
    );
}

}

这个页面就不能显示了,啥也没有 其它页面也是这样
import React, { Component } from 'react'
import { View, Text } from 'react-native'
import { WebView } from 'react-native-webview'

export default class TestWebViewPage extends Component {

render() {
    console.log(WebView)
    return (
        <View>
            <Text>出不来啊啊啊呀</Text>
            <WebView source={{ url: 'https://dev.mi.com/console/' }} />
        </View>
    )
}

}

阅读 5.8k
1 个回答

原来是uri不是url...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题