-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathCJNotification.java
31 lines (26 loc) · 1017 Bytes
/
CJNotification.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.rnprojectplayground;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
public class CJNotification {
// 统一 Native 到 JavaScript 的事件名称
final static private String NATIVE_TO_RN_EVENT = "NATIVE_TO_RN";
public static ReactContext reactContext;
/**
* 发送事件到 Javascript
* @param event 事件名称
* @param params 发送内容
*/
public static void sendRNEvent(String event, WritableMap params) {
if (reactContext != null) {
WritableMap body = Arguments.createMap();
body.putString("eventName", event);
if (params != null) {
body.putMap("body", params);
}
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(NATIVE_TO_RN_EVENT, body);
}
}
}