最近用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>
)
}
}
原来是uri不是url...