Procházet zdrojové kódy

fix(onShouldStartLoadWithRequest): android event was missing fields (#385)

`onShouldStartLoadWithRequest` event had only `url` in payload on android.
I've fixed it according to js event definition. 
https://github.com/react-native-community/react-native-webview/blob/master/js/WebViewTypes.js#L34
Stanislav Shakirov před 5 roky
rodič
revize
a25997bf65

+ 7
- 3
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Zobrazit soubor

@@ -159,7 +159,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
159 159
 
160 160
     @Override
161 161
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
162
-      dispatchEvent(view, new TopShouldStartLoadWithRequestEvent(view.getId(), url));
162
+      dispatchEvent(
163
+          view,
164
+          new TopShouldStartLoadWithRequestEvent(
165
+                  view.getId(),
166
+                  createWebViewEvent(view, url)));
163 167
       return true;
164 168
     }
165 169
 
@@ -167,8 +171,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
167 171
     @TargetApi(Build.VERSION_CODES.N)
168 172
     @Override
169 173
     public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
170
-      dispatchEvent(view, new TopShouldStartLoadWithRequestEvent(view.getId(), request.getUrl().toString()));
171
-      return true;
174
+      final String url = request.getUrl().toString();
175
+      return this.shouldOverrideUrlLoading(view, url);
172 176
     }
173 177
 
174 178
     @Override

+ 0
- 40
android/src/main/java/com/reactnativecommunity/webview/events/TopShouldStartLoadWithRequestEvent.java Zobrazit soubor

@@ -1,40 +0,0 @@
1
-package com.reactnativecommunity.webview.events;
2
-
3
-import com.facebook.react.bridge.Arguments;
4
-import com.facebook.react.bridge.WritableMap;
5
-import com.facebook.react.uimanager.events.Event;
6
-import com.facebook.react.uimanager.events.RCTEventEmitter;
7
-
8
-public class TopShouldStartLoadWithRequestEvent extends Event<TopMessageEvent> {
9
-    public static final String EVENT_NAME = "topShouldStartLoadWithRequest";
10
-    private final String mUrl;
11
-
12
-    public TopShouldStartLoadWithRequestEvent(int viewId, String url) {
13
-        super(viewId);
14
-        mUrl = url;
15
-    }
16
-
17
-    @Override
18
-    public String getEventName() {
19
-        return EVENT_NAME;
20
-    }
21
-
22
-    @Override
23
-    public boolean canCoalesce() {
24
-        return false;
25
-    }
26
-
27
-    @Override
28
-    public short getCoalescingKey() {
29
-        // All events for a given view can be coalesced.
30
-        return 0;
31
-    }
32
-
33
-    @Override
34
-    public void dispatch(RCTEventEmitter rctEventEmitter) {
35
-        WritableMap data = Arguments.createMap();
36
-        data.putString("url", mUrl);
37
-        data.putString("navigationType", "other");
38
-        rctEventEmitter.receiveEvent(getViewTag(), EVENT_NAME, data);
39
-    }
40
-}

+ 27
- 0
android/src/main/java/com/reactnativecommunity/webview/events/TopShouldStartLoadWithRequestEvent.kt Zobrazit soubor

@@ -0,0 +1,27 @@
1
+package com.reactnativecommunity.webview.events
2
+
3
+import com.facebook.react.bridge.WritableMap
4
+import com.facebook.react.uimanager.events.Event
5
+import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+/**
8
+ * Event emitted when shouldOverrideUrlLoading is called
9
+ */
10
+class TopShouldStartLoadWithRequestEvent(viewId: Int, private val mData: WritableMap) : Event<TopShouldStartLoadWithRequestEvent>(viewId) {
11
+    companion object {
12
+        const val EVENT_NAME = "topShouldStartLoadWithRequest"
13
+    }
14
+
15
+    init {
16
+        mData.putString("navigationType", "other")
17
+    }
18
+
19
+    override fun getEventName(): String = EVENT_NAME
20
+
21
+    override fun canCoalesce(): Boolean = false
22
+
23
+    override fun getCoalescingKey(): Short = 0
24
+
25
+    override fun dispatch(rctEventEmitter: RCTEventEmitter) =
26
+            rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, mData)
27
+}