lucasferreira / react-native-webview-android

Simple React Native Android module to use Android's WebView inside your app
355 stars 158 forks source link

Added support for onShouldStartLoadWithRequest. #98

Closed iamarkdev closed 6 years ago

iamarkdev commented 6 years ago

This adds a solution to react-native-webview-android for onShouldStartLoadWithRequest support.

The approach is fairly straightforward.

For any URL load, shouldOverrideUrlLoading will initially return true - not allowing it to load. It will also dispatch the ShouldOverrideUrlLoadingEvent, triggering _onShouldOverrideUrlLoading in index.android.js. It then gets the result of onShouldStartLoadWithRequest at the react-native level if it's set on RNWebViewAndroid. A view manager command is sent back to the native side, which will take the onShouldStartLoadWithRequest result as shouldOverride included in the command and either allow the original url to load, or not load.

To note, onShouldStartLoadWithRequest only receives an object containing url and navigationState in this initial implementation.

iamarkdev commented 6 years ago

Thanks @lucasferreira could you bump the npm version as well and publish it?

lucasferreira commented 6 years ago

OK @braydo25 thanks for that ;)

Couldn't test at all, but I've merged this believing in your need and already published in npm.

iamarkdev commented 6 years ago

Great! All should be well - I did extensive testing prior to submitting the PR

sinhpn92 commented 6 years ago

Have any solution to solve this issue? I did check latest version but didn't any update for this issue.

lucasferreira commented 6 years ago

It's already published @sinhpn92

https://github.com/lucasferreira/react-native-webview-android/blob/master/index.android.js#L46