mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 03:31:05 +00:00
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:
committed by
Thibault Malbranche
parent
e6125e4acc
commit
fc59cae4bf
@@ -107,6 +107,7 @@ import javax.annotation.Nullable;
|
||||
@ReactModule(name = RNCWebViewManager.REACT_CLASS)
|
||||
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_FORWARD = 2;
|
||||
public static final int COMMAND_RELOAD = 3;
|
||||
@@ -693,6 +694,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
activeUrl = url;
|
||||
dispatchEvent(
|
||||
view,
|
||||
new TopShouldStartLoadWithRequestEvent(
|
||||
@@ -847,9 +849,18 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
@Override
|
||||
public void onProgressChanged(WebView webView, int newProgress) {
|
||||
super.onProgressChanged(webView, newProgress);
|
||||
final String url = webView.getUrl();
|
||||
if (
|
||||
url != null
|
||||
&& activeUrl != null
|
||||
&& !url.equals(activeUrl)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
WritableMap event = Arguments.createMap();
|
||||
event.putDouble("target", webView.getId());
|
||||
event.putString("title", webView.getTitle());
|
||||
event.putString("url", url);
|
||||
event.putBoolean("canGoBack", webView.canGoBack());
|
||||
event.putBoolean("canGoForward", webView.canGoForward());
|
||||
event.putDouble("progress", (float) newProgress / 100);
|
||||
|
||||
Reference in New Issue
Block a user