fix(android): onMessage on android to return baseEvent(#755)

This commit is contained in:
SiDevesh 2019-08-02 13:36:11 +05:30 committed by Thibault Malbranche
parent cc17e65904
commit 282f81dcdd
2 changed files with 18 additions and 6 deletions

View File

@ -915,7 +915,21 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
}
public void onMessage(String message) {
dispatchEvent(this, new TopMessageEvent(this.getId(), message));
if (mRNCWebViewClient != null) {
WebView webView = this;
webView.post(new Runnable() {
@Override
public void run() {
WritableMap data = mRNCWebViewClient.createWebViewEvent(webView, webView.getUrl());
data.putString("data", message);
dispatchEvent(webView, new TopMessageEvent(webView.getId(), data));
}
});
} else {
WritableMap eventData = Arguments.createMap();
eventData.putString("data", message);
dispatchEvent(this, new TopMessageEvent(this.getId(), eventData));
}
}
protected void onScrollChanged(int x, int y, int oldX, int oldY) {

View File

@ -1,13 +1,13 @@
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
/**
* Event emitted when there is an error in loading.
*/
class TopMessageEvent(viewId: Int, private val mData: String) : Event<TopMessageEvent>(viewId) {
class TopMessageEvent(viewId: Int, private val mEventData: WritableMap) : Event<TopMessageEvent>(viewId) {
companion object {
const val EVENT_NAME = "topMessage"
}
@ -19,8 +19,6 @@ class TopMessageEvent(viewId: Int, private val mData: String) : Event<TopMessage
override fun getCoalescingKey(): Short = 0
override fun dispatch(rctEventEmitter: RCTEventEmitter) {
val data = Arguments.createMap()
data.putString("data", mData)
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, data)
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, mEventData)
}
}