Quellcode durchsuchen

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
Tyler Alves vor 5 Jahren
Ursprung
Commit
fc59cae4bf

+ 11
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Datei anzeigen

@@ -107,6 +107,7 @@ import javax.annotation.Nullable;
107 107
 @ReactModule(name = RNCWebViewManager.REACT_CLASS)
108 108
 public class RNCWebViewManager extends SimpleViewManager<WebView> {
109 109
 
110
+  public static String activeUrl = null;
110 111
   public static final int COMMAND_GO_BACK = 1;
111 112
   public static final int COMMAND_GO_FORWARD = 2;
112 113
   public static final int COMMAND_RELOAD = 3;
@@ -693,6 +694,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
693 694
 
694 695
     @Override
695 696
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
697
+      activeUrl = url;
696 698
       dispatchEvent(
697 699
         view,
698 700
         new TopShouldStartLoadWithRequestEvent(
@@ -847,9 +849,18 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
847 849
     @Override
848 850
     public void onProgressChanged(WebView webView, int newProgress) {
849 851
       super.onProgressChanged(webView, newProgress);
852
+      final String url = webView.getUrl();
853
+      if (
854
+        url != null
855
+        && activeUrl != null
856
+        && !url.equals(activeUrl)
857
+      ) {
858
+        return;
859
+      }
850 860
       WritableMap event = Arguments.createMap();
851 861
       event.putDouble("target", webView.getId());
852 862
       event.putString("title", webView.getTitle());
863
+      event.putString("url", url);
853 864
       event.putBoolean("canGoBack", webView.canGoBack());
854 865
       event.putBoolean("canGoForward", webView.canGoForward());
855 866
       event.putDouble("progress", (float) newProgress / 100);

+ 0
- 4
docs/Reference.md Datei anzeigen

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