The Method Stoploading Of React-native-webview Causes The Website To Freeze
Solution 1:
I have found a solution at least for my case thanks to this pull request. Instead of using onNavigationStateChange
and stopLoading
I turned to onShouldStartLoadWithRequest
.
In the callback method for this event you can define whether or not the request should be discarded as far as the current webview is concerned or not simply by returning false
or true
. So you get something like this:
render() {
...
return(...
<WebView
...
onShouldStartLoadWithRequest={this.handleWebViewRequest.bind(this)}
...
/>
);
}
handleWebViewRequest = request => {
const {url} = request;
if (!url) returnfalse;
if (isExternal(url)) {
Linking.openURL(url);
returnfalse;
} else {
returntrue;
}
}
So far for the "what to do"-part. Well I also wanted to answer my other questions and dug into the code of react-native-webview (which was no fun at all... what about comments? -> 'let the code speak' -> well it doesn't). After spending some time jumping from one delegation target to the next, somewhere the stopLoading
-call seems to be handed over to the native WebView. So the behaviour may also be completely different for Android and iOS (I'm developing only for Android currently). As for the "can I prevent"-part of the whole question I can say: "No".
Of course the most interesting part would have been "what does stopLoading
actually do? Somewhere I read that it prevents Links on the current page from being clicked, indeed. But that was just a non-proven statement. As I got to the native Android-WebView-documentation I found the very very good explanation "Stops the current load." (go Google, yay). Then I lost all motivation to dig deeper.
Well, unless someone more enlightned than me, can come up with a more elaborate explanation I will problably accept my own answer, since it is at least a solution to the dev-problem I faced.
Post a Comment for "The Method Stoploading Of React-native-webview Causes The Website To Freeze"