Skip to content
Permalink
Browse files

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
  • Loading branch information...
punksta authored and Titozzz committed Mar 13, 2019
1 parent 455e22e commit a25997bf65196d3dad857cb07ab8ae89f7a34407
@@ -159,16 +159,20 @@ public void onPageStarted(WebView webView, String url, Bitmap favicon) {

@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;
}


@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

This file was deleted.

@@ -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)
}

0 comments on commit a25997b

Please sign in to comment.
You can’t perform that action at this time.