Skip to content

Commit

Permalink
fix(onShouldStartLoadWithRequest): android event was missing fields (#…
Browse files Browse the repository at this point in the history
…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 a25997b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 43 deletions.
Expand Up @@ -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
Expand Down

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.