From b9046081ace89a2d3d0795c15920b6b2692c7702 Mon Sep 17 00:00:00 2001 From: Juan Pablo Garcia Dalolla Date: Wed, 13 Nov 2019 06:26:12 -0300 Subject: [PATCH] Add missing commandName field (#5643) --- .../react/EventEmitter.java | 3 ++- .../react/NavigationModule.java | 22 +++++++++---------- .../utils/NativeCommandListener.java | 6 +++-- .../utils/NativeCommandListenerTest.java | 5 +++-- lib/src/interfaces/Events.ts | 1 + 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/react/EventEmitter.java b/lib/android/app/src/main/java/com/reactnativenavigation/react/EventEmitter.java index 449000834bc..ae83e9a1414 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/react/EventEmitter.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/react/EventEmitter.java @@ -58,8 +58,9 @@ public void emitBottomTabSelected(int unselectedTabIndex, int selectedTabIndex) emit(BottomTabSelected, event); } - public void emitCommandCompleted(String commandId, long completionTime) { + public void emitCommandCompleted(String commandName, String commandId, long completionTime) { WritableMap event = Arguments.createMap(); + event.putString("commandName", commandName); event.putString("commandId", commandId); event.putDouble("completionTime", completionTime); emit(CommandCompleted, event); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java b/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java index 0caedb9b768..8bdd99269f0 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java @@ -94,7 +94,7 @@ public void setRoot(String commandId, ReadableMap rawLayoutTree, Promise promise final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree).optJSONObject("root")); handle(() -> { final ViewController viewController = layoutFactory.create(layoutTree); - navigator().setRoot(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now), reactInstanceManager); + navigator().setRoot(viewController, new NativeCommandListener("setRoot", commandId, promise, eventEmitter, now), reactInstanceManager); }); } @@ -117,7 +117,7 @@ public void push(String commandId, String onComponentId, ReadableMap rawLayoutTr final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree)); handle(() -> { final ViewController viewController = layoutFactory.create(layoutTree); - navigator().push(onComponentId, viewController, new NativeCommandListener(commandId, promise, eventEmitter, now)); + navigator().push(onComponentId, viewController, new NativeCommandListener("push", commandId, promise, eventEmitter, now)); }); } @@ -129,23 +129,23 @@ public void setStackRoot(String commandId, String onComponentId, ReadableArray c final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(children.getMap(i))); _children.add(layoutFactory.create(layoutTree)); } - navigator().setStackRoot(onComponentId, _children, new NativeCommandListener(commandId, promise, eventEmitter, now)); + navigator().setStackRoot(onComponentId, _children, new NativeCommandListener("setStackRoot", commandId, promise, eventEmitter, now)); }); } @ReactMethod public void pop(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) { - handle(() -> navigator().pop(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now))); + handle(() -> navigator().pop(componentId, parse(mergeOptions), new NativeCommandListener("pop", commandId, promise, eventEmitter, now))); } @ReactMethod public void popTo(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) { - handle(() -> navigator().popTo(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now))); + handle(() -> navigator().popTo(componentId, parse(mergeOptions), new NativeCommandListener("popTo", commandId, promise, eventEmitter, now))); } @ReactMethod public void popToRoot(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) { - handle(() -> navigator().popToRoot(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now))); + handle(() -> navigator().popToRoot(componentId, parse(mergeOptions), new NativeCommandListener("popToRoot", commandId, promise, eventEmitter, now))); } @ReactMethod @@ -153,7 +153,7 @@ public void showModal(String commandId, ReadableMap rawLayoutTree, Promise promi final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree)); handle(() -> { final ViewController viewController = layoutFactory.create(layoutTree); - navigator().showModal(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now)); + navigator().showModal(viewController, new NativeCommandListener("showModal", commandId, promise, eventEmitter, now)); }); } @@ -161,13 +161,13 @@ public void showModal(String commandId, ReadableMap rawLayoutTree, Promise promi public void dismissModal(String commandId, String componentId, @Nullable ReadableMap mergeOptions, Promise promise) { handle(() -> { navigator().mergeOptions(componentId, parse(mergeOptions)); - navigator().dismissModal(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now)); + navigator().dismissModal(componentId, new NativeCommandListener("dismissModal", commandId, promise, eventEmitter, now)); }); } @ReactMethod public void dismissAllModals(String commandId, @Nullable ReadableMap mergeOptions, Promise promise) { - handle(() -> navigator().dismissAllModals(parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now))); + handle(() -> navigator().dismissAllModals(parse(mergeOptions), new NativeCommandListener("dismissAllModals", commandId, promise, eventEmitter, now))); } @ReactMethod @@ -175,13 +175,13 @@ public void showOverlay(String commandId, ReadableMap rawLayoutTree, Promise pro final LayoutNode layoutTree = LayoutNodeParser.parse(jsonParser.parse(rawLayoutTree)); handle(() -> { final ViewController viewController = layoutFactory.create(layoutTree); - navigator().showOverlay(viewController, new NativeCommandListener(commandId, promise, eventEmitter, now)); + navigator().showOverlay(viewController, new NativeCommandListener("showOverlay", commandId, promise, eventEmitter, now)); }); } @ReactMethod public void dismissOverlay(String commandId, String componentId, Promise promise) { - handle(() -> navigator().dismissOverlay(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now))); + handle(() -> navigator().dismissOverlay(componentId, new NativeCommandListener("dismissOverlay", commandId, promise, eventEmitter, now))); } private Navigator navigator() { diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/utils/NativeCommandListener.java b/lib/android/app/src/main/java/com/reactnativenavigation/utils/NativeCommandListener.java index 8ad8a38c15a..154b4fbf191 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/utils/NativeCommandListener.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/utils/NativeCommandListener.java @@ -7,11 +7,13 @@ public class NativeCommandListener extends CommandListenerAdapter { private String commandId; + private String commandName; @Nullable private Promise promise; private EventEmitter eventEmitter; private Now now; - public NativeCommandListener(String commandId, @Nullable Promise promise, EventEmitter eventEmitter, Now now) { + public NativeCommandListener(String commandName, String commandId, @Nullable Promise promise, EventEmitter eventEmitter, Now now) { + this.commandName = commandName; this.commandId = commandId; this.promise = promise; this.eventEmitter = eventEmitter; @@ -21,7 +23,7 @@ public NativeCommandListener(String commandId, @Nullable Promise promise, EventE @Override public void onSuccess(String childId) { if (promise != null) promise.resolve(childId); - eventEmitter.emitCommandCompleted(commandId, now.now()); + eventEmitter.emitCommandCompleted(commandName, commandId, now.now()); } @Override diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java index f27ad3c7643..27aa4ba1599 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/utils/NativeCommandListenerTest.java @@ -14,6 +14,7 @@ import static org.mockito.Mockito.when; public class NativeCommandListenerTest extends BaseTest { + private static final String COMMAND_NAME = "someCommandName"; private static final String COMMAND_ID = "someCommand"; private static final String CHILD_ID = "someChild"; private static final long NOW = 1535374334; @@ -27,7 +28,7 @@ public class NativeCommandListenerTest extends BaseTest { public void beforeEach() { promise = Mockito.mock(Promise.class); eventEmitter = Mockito.mock(EventEmitter.class); - uut = new NativeCommandListener(COMMAND_ID, promise, eventEmitter, mockNow()); + uut = new NativeCommandListener(COMMAND_NAME, COMMAND_ID, promise, eventEmitter, mockNow()); } @Test @@ -39,7 +40,7 @@ public void onSuccess() { @Test public void onSuccess_emitsNavigationEvent() { uut.onSuccess(CHILD_ID); - verify(eventEmitter, times(1)).emitCommandCompleted(COMMAND_ID, NOW); + verify(eventEmitter, times(1)).emitCommandCompleted(COMMAND_NAME, COMMAND_ID, NOW); } @Test diff --git a/lib/src/interfaces/Events.ts b/lib/src/interfaces/Events.ts index 401f87f2920..8c2beed45a5 100644 --- a/lib/src/interfaces/Events.ts +++ b/lib/src/interfaces/Events.ts @@ -1,4 +1,5 @@ export interface CommandCompletedEvent { + commandName: string; commandId: string; completionTime: number; params: any;