Browse Source

Fix appLaunched and button press events on Android

Both events broke in 104e3f97
Guy Carmeli 6 years ago
parent
commit
1d2680c5aa

+ 11
- 9
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationEvent.java View File

@@ -1,7 +1,5 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3
-import android.support.annotation.NonNull;
4
-
5 3
 import com.facebook.react.bridge.Arguments;
6 4
 import com.facebook.react.bridge.ReactContext;
7 5
 import com.facebook.react.bridge.WritableMap;
@@ -10,10 +8,11 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
10 8
 import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
11 9
 
12 10
 public class NavigationEvent {
13
-	private static final String onAppLaunched = "RNN.onAppLaunched";
11
+	private static final String onAppLaunched = "RNN.appLaunched";
14 12
 	private static final String componentDidAppear = "RNN.componentDidAppear";
15 13
 	private static final String componentDidDisappear = "RNN.componentDidDisappear";
16
-	private static final String onNavigationButtonPressed = "RNN.onNavigationButtonPressed";
14
+	private static final String nativeEvent = "RNN.nativeEvent";
15
+    private static final String buttonPressedEvent = "buttonPressed";
17 16
 
18 17
 	private final RCTDeviceEventEmitter emitter;
19 18
 
@@ -37,16 +36,19 @@ public class NavigationEvent {
37 36
 		WritableMap map = Arguments.createMap();
38 37
 		map.putString("componentId", id);
39 38
 		map.putString("componentName", componentName);
40
-
41 39
 		emit(componentDidAppear, map);
42 40
 	}
43 41
 
44 42
     public void sendOnNavigationButtonPressed(String id, String buttonId) {
45
-		WritableMap map = Arguments.createMap();
46
-		map.putString("componentId", id);
47
-		map.putString("buttonId", buttonId);
43
+		WritableMap params = Arguments.createMap();
44
+		params.putString("componentId", id);
45
+		params.putString("buttonId", buttonId);
46
+
47
+        WritableMap map = Arguments.createMap();
48
+        map.putString("name", buttonPressedEvent);
49
+        map.putMap("params", params);
48 50
 
49
-		emit(onNavigationButtonPressed, map);
51
+		emit(nativeEvent, map);
50 52
 	}
51 53
 
52 54
 	private void emit(String eventName) {

+ 1
- 1
playground/src/app.js View File

@@ -22,7 +22,7 @@ if (Platform.OS === 'android') {
22 22
 
23 23
 function start() {
24 24
   registerScreens();
25
-  Navigation.events().onAppLaunched(() => {
25
+  Navigation.events().registerAppLaunchedListener(() => {
26 26
     Navigation.setDefaultOptions({
27 27
       _animations: {
28 28
         startApp: {

+ 3
- 3
playground/src/screens/StaticLifecycleOverlay.js View File

@@ -10,17 +10,17 @@ class StaticLifecycleOverlay extends Component {
10 10
       text: 'nothing yet',
11 11
       events: []
12 12
     };
13
-    Navigation.events().componentDidAppear((componentId, componentName) => {
13
+    Navigation.events().registerComponentDidAppearListener((componentId, componentName) => {
14 14
       this.setState({
15 15
         events: [...this.state.events, { event: 'componentDidAppear', componentId, componentName }]
16 16
       });
17 17
     });
18
-    Navigation.events().componentDidDisappear((componentId, componentName) => {
18
+    Navigation.events().registerComponentDidDisappearListener((componentId, componentName) => {
19 19
       this.setState({
20 20
         events: [...this.state.events, { event: 'componentDidDisappear', componentId, componentName }]
21 21
       });
22 22
     });
23
-    Navigation.events().onNavigationCommand((name, params) => {
23
+    Navigation.events().registerCommandListener((name, params) => {
24 24
       // console.log('RNN', `name: ${JSON.stringify(name)}`);
25 25
       // console.log('RNN', `params: ${JSON.stringify(params)}`);
26 26
     });