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
This commit is contained in:
parent
455e22e3b3
commit
a25997bf65
|
@ -159,7 +159,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
dispatchEvent(view, new TopShouldStartLoadWithRequestEvent(view.getId(), url));
|
||||
dispatchEvent(
|
||||
view,
|
||||
new TopShouldStartLoadWithRequestEvent(
|
||||
view.getId(),
|
||||
createWebViewEvent(view, url)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -167,8 +171,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
@TargetApi(Build.VERSION_CODES.N)
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
dispatchEvent(view, new TopShouldStartLoadWithRequestEvent(view.getId(), request.getUrl().toString()));
|
||||
return true;
|
||||
final String url = request.getUrl().toString();
|
||||
return this.shouldOverrideUrlLoading(view, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.reactnativecommunity.webview.events;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.uimanager.events.Event;
|
||||
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
|
||||
public class TopShouldStartLoadWithRequestEvent extends Event<TopMessageEvent> {
|
||||
public static final String EVENT_NAME = "topShouldStartLoadWithRequest";
|
||||
private final String mUrl;
|
||||
|
||||
public TopShouldStartLoadWithRequestEvent(int viewId, String url) {
|
||||
super(viewId);
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventName() {
|
||||
return EVENT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCoalesce() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getCoalescingKey() {
|
||||
// All events for a given view can be coalesced.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatch(RCTEventEmitter rctEventEmitter) {
|
||||
WritableMap data = Arguments.createMap();
|
||||
data.putString("url", mUrl);
|
||||
data.putString("navigationType", "other");
|
||||
rctEventEmitter.receiveEvent(getViewTag(), EVENT_NAME, data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.reactnativecommunity.webview.events
|
||||
|
||||
import com.facebook.react.bridge.WritableMap
|
||||
import com.facebook.react.uimanager.events.Event
|
||||
import com.facebook.react.uimanager.events.RCTEventEmitter
|
||||
|
||||
/**
|
||||
* Event emitted when shouldOverrideUrlLoading is called
|
||||
*/
|
||||
class TopShouldStartLoadWithRequestEvent(viewId: Int, private val mData: WritableMap) : Event<TopShouldStartLoadWithRequestEvent>(viewId) {
|
||||
companion object {
|
||||
const val EVENT_NAME = "topShouldStartLoadWithRequest"
|
||||
}
|
||||
|
||||
init {
|
||||
mData.putString("navigationType", "other")
|
||||
}
|
||||
|
||||
override fun getEventName(): String = EVENT_NAME
|
||||
|
||||
override fun canCoalesce(): Boolean = false
|
||||
|
||||
override fun getCoalescingKey(): Short = 0
|
||||
|
||||
override fun dispatch(rctEventEmitter: RCTEventEmitter) =
|
||||
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, mData)
|
||||
}
|
Loading…
Reference in New Issue