|
@@ -6,10 +6,14 @@ import android.content.Context;
|
6
|
6
|
import com.facebook.react.LifecycleState;
|
7
|
7
|
import com.facebook.react.ReactInstanceManager;
|
8
|
8
|
import com.facebook.react.ReactPackage;
|
|
9
|
+import com.facebook.react.bridge.ReactContext;
|
9
|
10
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
11
|
+import com.facebook.react.bridge.WritableMap;
|
10
|
12
|
|
11
|
13
|
import java.util.List;
|
12
|
14
|
|
|
15
|
+import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
|
|
16
|
+
|
13
|
17
|
/**
|
14
|
18
|
* Created by guyc on 22/02/16.
|
15
|
19
|
*/
|
|
@@ -85,4 +89,34 @@ public class RctManager {
|
85
|
89
|
|
86
|
90
|
return mReactManager.getCurrentReactContext().getNativeModule(nativeModuleClass);
|
87
|
91
|
}
|
|
92
|
+
|
|
93
|
+ /**
|
|
94
|
+ * Sends an event to JavaScript using <a href="https://facebook.github.io/react-native/docs/native-modules-android.html#sending-events-to-javascript">RCTDeviceEventEmitter</a>
|
|
95
|
+ * @param eventName Name of the event
|
|
96
|
+ * @param params Event params
|
|
97
|
+ * @param navigatorEventId Id of the navigator
|
|
98
|
+ */
|
|
99
|
+ public void sendEvent(String eventName, String navigatorEventId, WritableMap params) {
|
|
100
|
+ RCTDeviceEventEmitter eventEmitter = getEventEmitter();
|
|
101
|
+ if (eventEmitter == null) {
|
|
102
|
+ return;
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ params.putString(KEY_EVENT_ID, eventName);
|
|
106
|
+ eventEmitter.emit(navigatorEventId, params);
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ private RCTDeviceEventEmitter getEventEmitter() {
|
|
110
|
+ if (mReactManager == null) {
|
|
111
|
+ return null;
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ ReactContext currentReactContext = mReactManager.getCurrentReactContext();
|
|
115
|
+ if (currentReactContext == null) {
|
|
116
|
+ return null;
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ return currentReactContext.getJSModule(RCTDeviceEventEmitter.class);
|
|
120
|
+ }
|
88
|
121
|
}
|
|
122
|
+
|