fix(android): onMessage on android to return baseEvent(#755)
This commit is contained in:
parent
cc17e65904
commit
282f81dcdd
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue