Skip to content

Commit

Permalink
Add missing commandName field (#5643)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgarcia authored and guyca committed Nov 13, 2019
1 parent d6e2281 commit b904608
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand All @@ -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));
});
}

Expand All @@ -129,59 +129,59 @@ 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
public void showModal(String commandId, ReadableMap rawLayoutTree, Promise promise) {
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));
});
}

@ReactMethod
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
public void showOverlay(String commandId, ReadableMap rawLayoutTree, Promise promise) {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/src/interfaces/Events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface CommandCompletedEvent {
commandName: string;
commandId: string;
completionTime: number;
params: any;
Expand Down

0 comments on commit b904608

Please sign in to comment.