【发布时间】:2019-08-27 08:57:23
【问题描述】:
我正在使用react-native-webview 来呈现网页视图。当我在 web 视图中从一个页面导航到另一个页面然后尝试使用 this.webviewref.goBack() 返回时,我得到了 nodeHandle expected to be non-null 的异常。
这是我的一段代码
<View style={{ flex: 1 }}>
<Header
headingText={headerText}
onpress={() => {
// this.dispatchCustomEvent(BACK_PRESS);
if (this.canGoBack) {
this.webViewRef.goBack();
} else NavigationActions.pop();
}}
/>
<WebView
source={{ uri: "http://localhost:3001/invite/" }}
bounces={false}
javaScriptEnabled={true}
ref={webViewRef => (this.webViewRef = webViewRef)}
// injectedJavaScript={patchPostMessageJsCode}
onMessage={event => {
const { type, data } = JSON.parse(event.nativeEvent.data);
console.log({ type });
console.log({ data });
this.handleEvent(type, data);
}}
onNavigationStateChange={navState =>
(this.canGoBack = navState.canGoBack)
}
/>
</View>
控制台日志this.webViewRef显示goBack方法存在于weViewRef中
抛出nodeHandle expected to be non-null的代码可以在这里找到https://github.com/react-native-community/react-native-webview/blob/master/src/WebView.ios.tsx
我无法理解getWebViewHandle 有什么问题
以及为什么nodeHandle 为空。
【问题讨论】:
标签: ios react-native webview react-native-webview