/// <summary> /// Executes back action depending on top-most frame state. /// </summary> /// <remarks> /// Priorities: /// <list type="number"> /// <item>Navigates back within the modal, if possible.</item> /// <item>Closes the modal, if possible.</item> /// <item>Navigates back within a section.</item> /// </list> /// This is useful when dealing with hardware back buttons. /// </remarks> /// <param name="sectionsNavigator">The sections navigator.</param> /// <param name="ct">The cancellation token.</param> public static async Task NavigateBackOrCloseModal(this ISectionsNavigator sectionsNavigator, CancellationToken ct) { if (sectionsNavigator.State.ActiveModal?.CanNavigateBack() ?? false) { await sectionsNavigator.State.ActiveModal.NavigateBack(ct); } else if (sectionsNavigator.State.ActiveModal != null) { await sectionsNavigator.CloseModal(ct); } else if (sectionsNavigator.State.ActiveSection?.CanNavigateBack() ?? false) { await sectionsNavigator.State.ActiveSection.NavigateBack(ct); } else { throw new InvalidOperationException($"Failed to NavigateBack or CloseModal. The active section '{sectionsNavigator.State.ActiveSection?.Name ?? "null"}' can't currently navigate back and there are no modals to close."); } }
/// <summary> /// Closes the top-most modal. /// </summary> /// <param name="sectionsNavigator">The sections navigator.</param> /// <param name="ct">The cancellation token.</param> public static async Task CloseModal(this ISectionsNavigator sectionsNavigator, CancellationToken ct) { await sectionsNavigator.CloseModal(ct, SectionsNavigatorRequest.GetCloseModalRequest(modalPriority: null)); }