React-Native-Webview:预期nodeHandle不为null

问题描述 投票:0回答:1

我使用react-native-webview渲染webview。当我从webview中的一个页面导航到另一个页面然后尝试使用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显示weazRef中存在goBack方法

投掷nodeHandle expected to be non-null的代码可以在这里找到https://github.com/react-native-community/react-native-webview/blob/master/src/WebView.ios.tsx

我无法理解getWebViewHandle的问题是什么,为什么nodeHandle为null。

ios react-native webview react-native-webview
1个回答
1
投票

我有同样的问题。事实证明,我的react-native版本太低了。它需要至少0.57。升级到0.59.5和其他依赖项后,此问题消失。

© www.soinside.com 2019 - 2024. All rights reserved.