Browse Source

Changes to event emitter

Guy Carmeli 8 years ago
parent
commit
1a91372a0a

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

5
 import android.support.annotation.NonNull;
5
 import android.support.annotation.NonNull;
6
 
6
 
7
 import com.facebook.react.ReactPackage;
7
 import com.facebook.react.ReactPackage;
8
+import com.facebook.react.bridge.ReactContext;
9
+import com.facebook.react.bridge.WritableMap;
8
 import com.facebook.react.shell.MainReactPackage;
10
 import com.facebook.react.shell.MainReactPackage;
9
 import com.reactnativenavigation.bridge.NavigationReactPackage;
11
 import com.reactnativenavigation.bridge.NavigationReactPackage;
10
 import com.reactnativenavigation.react.NavigationReactInstance;
12
 import com.reactnativenavigation.react.NavigationReactInstance;
66
         return "index.android.bundle";
68
         return "index.android.bundle";
67
     }
69
     }
68
 
70
 
71
+    public ReactContext getReactContext() {
72
+        return navigationReactInstance.getReactInstanceManager().getCurrentReactContext();
73
+    }
74
+
69
     public abstract boolean isDebug();
75
     public abstract boolean isDebug();
70
 
76
 
71
     @NonNull
77
     @NonNull
72
     public abstract List<ReactPackage> createAdditionalReactPackages();
78
     public abstract List<ReactPackage> createAdditionalReactPackages();
73
 
79
 
80
+    public void sendNavigatorEvent(String eventId, String navigatorEventId) {
81
+        navigationReactInstance.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId);
82
+    }
83
+
74
     public void sendEvent(String eventId, String navigatorEventId) {
84
     public void sendEvent(String eventId, String navigatorEventId) {
75
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
85
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
76
     }
86
     }
77
 
87
 
88
+    public void sendNavigatorEvent(String eventId, WritableMap arguments) {
89
+        navigationReactInstance.getReactEventEmitter().sendEvent(eventId, arguments);
90
+    }
91
+
78
     public void startReactContext() {
92
     public void startReactContext() {
79
         navigationReactInstance = new NavigationReactInstance();
93
         navigationReactInstance = new NavigationReactInstance();
80
         navigationReactInstance.startReactContextOnceInBackgroundAndExecuteJS();
94
         navigationReactInstance.startReactContextOnceInBackgroundAndExecuteJS();

+ 14
- 6
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactEventEmitter.java View File

17
         this.eventEmitter = reactContext.getJSModule(RCTDeviceEventEmitter.class);
17
         this.eventEmitter = reactContext.getJSModule(RCTDeviceEventEmitter.class);
18
     }
18
     }
19
 
19
 
20
-    public void sendEvent(String eventId, String navigatorEventId) {
21
-        WritableMap params = Arguments.createMap();
22
-        params.putString(KEY_EVENT_TYPE, EVENT_TYPE);
23
-        params.putString(KEY_EVENT_ID, eventId);
24
-        params.putString(KEY_NAVIGATOR_EVENT_ID, navigatorEventId);
25
-        eventEmitter.emit(navigatorEventId, params);
20
+    public void sendNavigatorEvent(String eventId, String navigatorEventId) {
21
+        WritableMap data = Arguments.createMap();
22
+        data.putString(KEY_EVENT_TYPE, EVENT_TYPE);
23
+        data.putString(KEY_EVENT_ID, eventId);
24
+        data.putString(KEY_NAVIGATOR_EVENT_ID, navigatorEventId);
25
+        eventEmitter.emit(navigatorEventId, data);
26
+    }
27
+
28
+    public void sendEvent(String eventId, String data) {
29
+        eventEmitter.emit(eventId, data);
30
+    }
31
+
32
+    public void sendEvent(String eventId, WritableMap data) {
33
+        eventEmitter.emit(eventId, data);
26
     }
34
     }
27
 }
35
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/LeftButton.java View File

63
     }
63
     }
64
 
64
 
65
     private void sendClickEvent() {
65
     private void sendClickEvent() {
66
-        NavigationApplication.instance.sendEvent(params.eventId, navigatorEventId);
66
+        NavigationApplication.instance.sendNavigatorEvent(params.eventId, navigatorEventId);
67
     }
67
     }
68
 }
68
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java View File

92
 
92
 
93
     @Override
93
     @Override
94
     public boolean onMenuItemClick(MenuItem item) {
94
     public boolean onMenuItemClick(MenuItem item) {
95
-        NavigationApplication.instance.sendEvent(buttonParams.eventId, navigatorEventId);
95
+        NavigationApplication.instance.sendNavigatorEvent(buttonParams.eventId, navigatorEventId);
96
         return true;
96
         return true;
97
     }
97
     }
98
 }
98
 }