Browse Source

Add missing commandName field (#5643)

Juan Pablo Garcia Dalolla 4 years ago
parent
commit
b9046081ac

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/EventEmitter.java View File

58
         emit(BottomTabSelected, event);
58
         emit(BottomTabSelected, event);
59
     }
59
     }
60
 
60
 
61
-    public void emitCommandCompleted(String commandId, long completionTime) {
61
+    public void emitCommandCompleted(String commandName, String commandId, long completionTime) {
62
         WritableMap event = Arguments.createMap();
62
         WritableMap event = Arguments.createMap();
63
+        event.putString("commandName", commandName);
63
         event.putString("commandId", commandId);
64
         event.putString("commandId", commandId);
64
         event.putDouble("completionTime", completionTime);
65
         event.putDouble("completionTime", completionTime);
65
         emit(CommandCompleted, event);
66
         emit(CommandCompleted, event);

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

94
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree).optJSONObject("root"));
94
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree).optJSONObject("root"));
95
         handle(() -> {
95
         handle(() -> {
96
             final ViewController viewController = layoutFactory.create(layoutTree);
96
             final ViewController viewController = layoutFactory.create(layoutTree);
97
-            navigator().setRoot(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now), reactInstanceManager);
97
+            navigator().setRoot(viewController, new NativeCommandListener("setRoot", commandId, promise, eventEmitter, now), reactInstanceManager);
98
         });
98
         });
99
     }
99
     }
100
 
100
 
117
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
117
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
118
         handle(() -> {
118
         handle(() -> {
119
             final ViewController viewController = layoutFactory.create(layoutTree);
119
             final ViewController viewController = layoutFactory.create(layoutTree);
120
-            navigator().push(onComponentId, viewController, new NativeCommandListener(commandId, promise, eventEmitter, now));
120
+            navigator().push(onComponentId, viewController, new NativeCommandListener("push", commandId, promise, eventEmitter, now));
121
         });
121
         });
122
     }
122
     }
123
 
123
 
129
                 final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(children.getMap(i)));
129
                 final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(children.getMap(i)));
130
                 _children.add(layoutFactory.create(layoutTree));
130
                 _children.add(layoutFactory.create(layoutTree));
131
             }
131
             }
132
-            navigator().setStackRoot(onComponentId, _children, new NativeCommandListener(commandId, promise, eventEmitter, now));
132
+            navigator().setStackRoot(onComponentId, _children, new NativeCommandListener("setStackRoot", commandId, promise, eventEmitter, now));
133
         });
133
         });
134
     }
134
     }
135
 
135
 
136
     @ReactMethod
136
     @ReactMethod
137
     public void pop(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
137
     public void pop(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
138
-        handle(() -> navigator().pop(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
138
+        handle(() -> navigator().pop(componentId, parse(mergeOptions), new NativeCommandListener("pop", commandId, promise, eventEmitter, now)));
139
     }
139
     }
140
 
140
 
141
     @ReactMethod
141
     @ReactMethod
142
     public void popTo(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
142
     public void popTo(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
143
-        handle(() -> navigator().popTo(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
143
+        handle(() -> navigator().popTo(componentId, parse(mergeOptions), new NativeCommandListener("popTo", commandId, promise, eventEmitter, now)));
144
     }
144
     }
145
 
145
 
146
     @ReactMethod
146
     @ReactMethod
147
     public void popToRoot(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
147
     public void popToRoot(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
148
-        handle(() -> navigator().popToRoot(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
148
+        handle(() -> navigator().popToRoot(componentId, parse(mergeOptions), new NativeCommandListener("popToRoot", commandId, promise, eventEmitter, now)));
149
     }
149
     }
150
 
150
 
151
     @ReactMethod
151
     @ReactMethod
153
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
153
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
154
         handle(() -> {
154
         handle(() -> {
155
             final ViewController viewController = layoutFactory.create(layoutTree);
155
             final ViewController viewController = layoutFactory.create(layoutTree);
156
-            navigator().showModal(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now));
156
+            navigator().showModal(viewController, new NativeCommandListener("showModal", commandId, promise, eventEmitter, now));
157
         });
157
         });
158
     }
158
     }
159
 
159
 
161
     public void dismissModal(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
161
     public void dismissModal(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
162
         handle(() -> {
162
         handle(() -> {
163
             navigator().mergeOptions(componentId, parse(mergeOptions));
163
             navigator().mergeOptions(componentId, parse(mergeOptions));
164
-            navigator().dismissModal(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now));
164
+            navigator().dismissModal(componentId, new NativeCommandListener("dismissModal", commandId, promise, eventEmitter, now));
165
         });
165
         });
166
     }
166
     }
167
 
167
 
168
     @ReactMethod
168
     @ReactMethod
169
     public void dismissAllModals(String commandId, @Nullable ReadableMap mergeOptions, Promise promise) {
169
     public void dismissAllModals(String commandId, @Nullable ReadableMap mergeOptions, Promise promise) {
170
-        handle(() -> navigator().dismissAllModals(parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
170
+        handle(() -> navigator().dismissAllModals(parse(mergeOptions), new NativeCommandListener("dismissAllModals", commandId, promise, eventEmitter, now)));
171
     }
171
     }
172
 
172
 
173
     @ReactMethod
173
     @ReactMethod
175
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
175
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
176
         handle(() -> {
176
         handle(() -> {
177
             final ViewController viewController = layoutFactory.create(layoutTree);
177
             final ViewController viewController = layoutFactory.create(layoutTree);
178
-            navigator().showOverlay(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now));
178
+            navigator().showOverlay(viewController, new NativeCommandListener("showOverlay", commandId, promise, eventEmitter, now));
179
         });
179
         });
180
     }
180
     }
181
 
181
 
182
     @ReactMethod
182
     @ReactMethod
183
     public void dismissOverlay(String commandId, String componentId, Promise promise) {
183
     public void dismissOverlay(String commandId, String componentId, Promise promise) {
184
-        handle(() -> navigator().dismissOverlay(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now)));
184
+        handle(() -> navigator().dismissOverlay(componentId, new NativeCommandListener("dismissOverlay", commandId, promise, eventEmitter, now)));
185
     }
185
     }
186
 
186
 
187
     private Navigator navigator() {
187
     private Navigator navigator() {

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/utils/NativeCommandListener.java View File

7
 
7
 
8
 public class NativeCommandListener extends CommandListenerAdapter {
8
 public class NativeCommandListener extends CommandListenerAdapter {
9
     private String commandId;
9
     private String commandId;
10
+    private String commandName;
10
     @Nullable private Promise promise;
11
     @Nullable private Promise promise;
11
     private EventEmitter eventEmitter;
12
     private EventEmitter eventEmitter;
12
     private Now now;
13
     private Now now;
13
 
14
 
14
-    public NativeCommandListener(String commandId, @Nullable Promise promise, EventEmitter eventEmitter, Now now) {
15
+    public NativeCommandListener(String commandName, String commandId, @Nullable Promise promise, EventEmitter eventEmitter, Now now) {
16
+        this.commandName = commandName;
15
         this.commandId = commandId;
17
         this.commandId = commandId;
16
         this.promise = promise;
18
         this.promise = promise;
17
         this.eventEmitter = eventEmitter;
19
         this.eventEmitter = eventEmitter;
21
     @Override
23
     @Override
22
     public void onSuccess(String childId) {
24
     public void onSuccess(String childId) {
23
         if (promise != null) promise.resolve(childId);
25
         if (promise != null) promise.resolve(childId);
24
-        eventEmitter.emitCommandCompleted(commandId, now.now());
26
+        eventEmitter.emitCommandCompleted(commandName, commandId, now.now());
25
     }
27
     }
26
 
28
 
27
     @Override
29
     @Override

+ 3
- 2
lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java View File

14
 import static org.mockito.Mockito.when;
14
 import static org.mockito.Mockito.when;
15
 
15
 
16
 public class NativeCommandListenerTest extends BaseTest {
16
 public class NativeCommandListenerTest extends BaseTest {
17
+    private static final String COMMAND_NAME = "someCommandName";
17
     private static final String COMMAND_ID = "someCommand";
18
     private static final String COMMAND_ID = "someCommand";
18
     private static final String CHILD_ID = "someChild";
19
     private static final String CHILD_ID = "someChild";
19
     private static final long NOW = 1535374334;
20
     private static final long NOW = 1535374334;
27
     public void beforeEach() {
28
     public void beforeEach() {
28
         promise = Mockito.mock(Promise.class);
29
         promise = Mockito.mock(Promise.class);
29
         eventEmitter = Mockito.mock(EventEmitter.class);
30
         eventEmitter = Mockito.mock(EventEmitter.class);
30
-        uut = new NativeCommandListener(COMMAND_ID, promise, eventEmitter, mockNow());
31
+        uut = new NativeCommandListener(COMMAND_NAME, COMMAND_ID, promise, eventEmitter, mockNow());
31
     }
32
     }
32
 
33
 
33
     @Test
34
     @Test
39
     @Test
40
     @Test
40
     public void onSuccess_emitsNavigationEvent() {
41
     public void onSuccess_emitsNavigationEvent() {
41
         uut.onSuccess(CHILD_ID);
42
         uut.onSuccess(CHILD_ID);
42
-        verify(eventEmitter, times(1)).emitCommandCompleted(COMMAND_ID, NOW);
43
+        verify(eventEmitter, times(1)).emitCommandCompleted(COMMAND_NAME, COMMAND_ID, NOW);
43
     }
44
     }
44
 
45
 
45
     @Test
46
     @Test

+ 1
- 0
lib/src/interfaces/Events.ts View File

1
 export interface CommandCompletedEvent {
1
 export interface CommandCompletedEvent {
2
+  commandName: string;
2
   commandId: string;
3
   commandId: string;
3
   completionTime: number;
4
   completionTime: number;
4
   params: any;
5
   params: any;