Explorar el Código

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 hace 4 años
padre
commit
fc59cae4bf

+ 11
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Ver fichero

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

+ 0
- 4
docs/Reference.md Ver fichero

311
 
311
 
312
 Function that is invoked when the `WebView` is loading.
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
 | Type     | Required |
314
 | Type     | Required |
319
 | -------- | -------- |
315
 | -------- | -------- |
320
 | function | No       |
316
 | function | No       |