class ModalStack {

    public boolean dismissModal(String componentId, @Nullable ViewController root, CommandListener listener) {
        ViewController toDismiss = findModalByComponentId(componentId);
        if (toDismiss != null) {
            boolean isDismissingTopModal = isTop(toDismiss);
            modals.remove(toDismiss);
            @Nullable ViewController toAdd = isEmpty() ? root : isDismissingTopModal ? get(size() - 1) : null;
            CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) {
                @Override
                public void onSuccess(String childId) {
                    eventEmitter.emitModalDismissed(componentId, 1);
                    super.onSuccess(componentId);
                }
            };
            if (isDismissingTopModal) {
                if (toAdd == null) {
                    listener.onError("Could not dismiss modal");
                    return false;
                }
            }
            presenter.dismissModal(toDismiss, toAdd, root, onDismiss);
            return true;
        } else {
            listener.onError("Nothing to dismiss");
            return false;
        }
    }

    public  ModalStack(Activity activity);
    @RestrictTo(RestrictTo.Scope.TESTS)  ModalStack(ModalPresenter presenter);

}