Pārlūkot izejas kodu

Add missing commandName field (#5643)

Juan Pablo Garcia Dalolla 5 gadus atpakaļ
vecāks
revīzija
b9046081ac

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/EventEmitter.java Parādīt failu

@@ -58,8 +58,9 @@ public class EventEmitter {
58 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 62
         WritableMap event = Arguments.createMap();
63
+        event.putString("commandName", commandName);
63 64
         event.putString("commandId", commandId);
64 65
         event.putDouble("completionTime", completionTime);
65 66
         emit(CommandCompleted, event);

+ 11
- 11
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java Parādīt failu

@@ -94,7 +94,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
94 94
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree).optJSONObject("root"));
95 95
         handle(() -> {
96 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,7 +117,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
117 117
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
118 118
         handle(() -> {
119 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,23 +129,23 @@ public class NavigationModule extends ReactContextBaseJavaModule {
129 129
                 final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(children.getMap(i)));
130 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 136
     @ReactMethod
137 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 141
     @ReactMethod
142 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 146
     @ReactMethod
147 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 151
     @ReactMethod
@@ -153,7 +153,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
153 153
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
154 154
         handle(() -> {
155 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,13 +161,13 @@ public class NavigationModule extends ReactContextBaseJavaModule {
161 161
     public void dismissModal(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) {
162 162
         handle(() -> {
163 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 168
     @ReactMethod
169 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 173
     @ReactMethod
@@ -175,13 +175,13 @@ public class NavigationModule extends ReactContextBaseJavaModule {
175 175
         final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree));
176 176
         handle(() -> {
177 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 182
     @ReactMethod
183 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 187
     private Navigator navigator() {

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/utils/NativeCommandListener.java Parādīt failu

@@ -7,11 +7,13 @@ import com.reactnativenavigation.react.EventEmitter;
7 7
 
8 8
 public class NativeCommandListener extends CommandListenerAdapter {
9 9
     private String commandId;
10
+    private String commandName;
10 11
     @Nullable private Promise promise;
11 12
     private EventEmitter eventEmitter;
12 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 17
         this.commandId = commandId;
16 18
         this.promise = promise;
17 19
         this.eventEmitter = eventEmitter;
@@ -21,7 +23,7 @@ public class NativeCommandListener extends CommandListenerAdapter {
21 23
     @Override
22 24
     public void onSuccess(String childId) {
23 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 29
     @Override

+ 3
- 2
lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java Parādīt failu

@@ -14,6 +14,7 @@ import static org.mockito.Mockito.verify;
14 14
 import static org.mockito.Mockito.when;
15 15
 
16 16
 public class NativeCommandListenerTest extends BaseTest {
17
+    private static final String COMMAND_NAME = "someCommandName";
17 18
     private static final String COMMAND_ID = "someCommand";
18 19
     private static final String CHILD_ID = "someChild";
19 20
     private static final long NOW = 1535374334;
@@ -27,7 +28,7 @@ public class NativeCommandListenerTest extends BaseTest {
27 28
     public void beforeEach() {
28 29
         promise = Mockito.mock(Promise.class);
29 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 34
     @Test
@@ -39,7 +40,7 @@ public class NativeCommandListenerTest extends BaseTest {
39 40
     @Test
40 41
     public void onSuccess_emitsNavigationEvent() {
41 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 46
     @Test

+ 1
- 0
lib/src/interfaces/Events.ts Parādīt failu

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