【问题标题】:Webivew onNavigationStateChange method call multiple time in react nativeWebview onNavigationStateChange方法在反应原生中多次调用
【发布时间】:2020-06-28 05:51:04
【问题描述】:

我正在制作反应本机应用程序和一个屏幕,我为此使用了 webview,我想处理 onNavigationStateChange 道具一次调用,现在它正在调用多次,所以知道如何解决这个问题。参考下面的代码

<WebView 
         ref={r => this.webview = r}
         style={{width:globals.screenWidth, height:globals.screenHeight}}
         bounces={false}
         style={{ flex: 1 }}
         startInLoadingState
         scalesPageToFit
         javaScriptEnabledAndroid={true}
         javaScriptEnabled={true}
         domStorageEnabled = {true}
         onNavigationStateChange={data =>
            this.handleNavigationStateChange(data)
        }
         onLoadStart={() => {
             console.log("onLoadStart-->");
         }}
         onLoadEnd={() => {
            console.log("onLoadEnd-->");
         }}
         source={{uri: globals.MYURL}}
         onError={(error) => this.onError()}
        />


handleNavigationStateChange = navState => {
    console.log("navState >>>>" + JSON.stringify(navState));

};

当我在上面运行代码 navState >>>> 打印 3 次时,我想处理 1 次,那么我该如何解决这个问题?您的所有建议都很有价值。

【问题讨论】:

    标签: android ios react-native webview


    【解决方案1】:

    我遇到了同样的问题,但我将句柄移到 onLoadEnd

    _onLoadEndHandle = (input) => {
       console.log(input.nativeEvent)
       if (input.nativeEvent.url.toLowerCase().includes('?type=print')) {
         console.log('printing...')
         this._print() // Calling printing function
       }
    }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多