Selaa lähdekoodia

Changes to event emitter

Guy Carmeli 8 vuotta sitten
vanhempi
commit
1a91372a0a

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java Näytä tiedosto

@@ -5,6 +5,8 @@ import android.os.Handler;
5 5
 import android.support.annotation.NonNull;
6 6
 
7 7
 import com.facebook.react.ReactPackage;
8
+import com.facebook.react.bridge.ReactContext;
9
+import com.facebook.react.bridge.WritableMap;
8 10
 import com.facebook.react.shell.MainReactPackage;
9 11
 import com.reactnativenavigation.bridge.NavigationReactPackage;
10 12
 import com.reactnativenavigation.react.NavigationReactInstance;
@@ -66,15 +68,27 @@ public abstract class NavigationApplication extends Application {
66 68
         return "index.android.bundle";
67 69
     }
68 70
 
71
+    public ReactContext getReactContext() {
72
+        return navigationReactInstance.getReactInstanceManager().getCurrentReactContext();
73
+    }
74
+
69 75
     public abstract boolean isDebug();
70 76
 
71 77
     @NonNull
72 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 84
     public void sendEvent(String eventId, String navigatorEventId) {
75 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 92
     public void startReactContext() {
79 93
         navigationReactInstance = new NavigationReactInstance();
80 94
         navigationReactInstance.startReactContextOnceInBackgroundAndExecuteJS();

+ 14
- 6
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactEventEmitter.java Näytä tiedosto

@@ -17,11 +17,19 @@ public class NavigationReactEventEmitter {
17 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 Näytä tiedosto

@@ -63,6 +63,6 @@ public class LeftButton extends MaterialMenuDrawable implements View.OnClickList
63 63
     }
64 64
 
65 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 Näytä tiedosto

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