fix(android): Filter extra onLoadProgress & add url event (#643)

* Filter out extra onLoadProgress calls; add url to onLoadProgress

* remove note about onLoadProgress not having the url property in docs

* Update Reference.md
This commit is contained in:
Tyler Alves 2019-09-23 01:35:49 -07:00 committed by Thibault Malbranche
parent e6125e4acc
commit fc59cae4bf
2 changed files with 11 additions and 4 deletions

View File

@ -107,6 +107,7 @@ import javax.annotation.Nullable;
@ReactModule(name = RNCWebViewManager.REACT_CLASS) @ReactModule(name = RNCWebViewManager.REACT_CLASS)
public class RNCWebViewManager extends SimpleViewManager<WebView> { public class RNCWebViewManager extends SimpleViewManager<WebView> {
public static String activeUrl = null;
public static final int COMMAND_GO_BACK = 1; public static final int COMMAND_GO_BACK = 1;
public static final int COMMAND_GO_FORWARD = 2; public static final int COMMAND_GO_FORWARD = 2;
public static final int COMMAND_RELOAD = 3; public static final int COMMAND_RELOAD = 3;
@ -693,6 +694,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
activeUrl = url;
dispatchEvent( dispatchEvent(
view, view,
new TopShouldStartLoadWithRequestEvent( new TopShouldStartLoadWithRequestEvent(
@ -847,9 +849,18 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@Override @Override
public void onProgressChanged(WebView webView, int newProgress) { public void onProgressChanged(WebView webView, int newProgress) {
super.onProgressChanged(webView, newProgress); super.onProgressChanged(webView, newProgress);
final String url = webView.getUrl();
if (
url != null
&& activeUrl != null
&& !url.equals(activeUrl)
) {
return;
}
WritableMap event = Arguments.createMap(); WritableMap event = Arguments.createMap();
event.putDouble("target", webView.getId()); event.putDouble("target", webView.getId());
event.putString("title", webView.getTitle()); event.putString("title", webView.getTitle());
event.putString("url", url);
event.putBoolean("canGoBack", webView.canGoBack()); event.putBoolean("canGoBack", webView.canGoBack());
event.putBoolean("canGoForward", webView.canGoForward()); event.putBoolean("canGoForward", webView.canGoForward());
event.putDouble("progress", (float) newProgress / 100); event.putDouble("progress", (float) newProgress / 100);

View File

@ -311,10 +311,6 @@ url
Function that is invoked when the `WebView` is loading. Function that is invoked when the `WebView` is loading.
> **_Note_**
>
> On android, You can't get the url property, meaning that `event.nativeEvent.url` will be null.
| Type | Required | | Type | Required |
| -------- | -------- | | -------- | -------- |
| function | No | | function | No |