diff --git a/samples/DemoApp/ViewModels/DemoTabsViewModel.cs b/samples/DemoApp/ViewModels/DemoTabsViewModel.cs index 1e6e92b..8f73602 100644 --- a/samples/DemoApp/ViewModels/DemoTabsViewModel.cs +++ b/samples/DemoApp/ViewModels/DemoTabsViewModel.cs @@ -3,6 +3,9 @@ namespace DemoApp.ViewModels; +/// +/// All three tabs (Alpha/Beta/Charlie), share this viewmodel. +/// public partial class DemoTabsViewModel : BaseViewModel { #region Constructors @@ -30,27 +33,27 @@ private async Task GoBack() /// Navigate to Alpha tab page. /// [RelayCommand] - private async Task SwitchToAlphaTabPage() + private void SwitchToAlphaTabPage() { - await navigationService.SelectTab(); + navigationService.SelectTab(); } /// /// Navigate to Beta tab page. /// [RelayCommand] - private async Task SwitchToBetaTabPage() + private void SwitchToBetaTabPage() { - await navigationService.SelectTab(); + navigationService.SelectTab(); } /// /// Navigate to Charlie tab page. /// [RelayCommand] - private async Task SwitchToCharlieTabPage() + private void SwitchToCharlieTabPage() { - await navigationService.SelectTab(); + navigationService.SelectTab(); } #endregion Commands diff --git a/samples/DemoApp/ViewModels/LoginViewModel.cs b/samples/DemoApp/ViewModels/LoginViewModel.cs index a8b90ab..cc2a917 100644 --- a/samples/DemoApp/ViewModels/LoginViewModel.cs +++ b/samples/DemoApp/ViewModels/LoginViewModel.cs @@ -53,6 +53,7 @@ private async Task Login() { "username", Username }, }; + // after we login, we replace the stack so the user can't go back to the Login page await navigationService.ResetStackAndPush(navigationParameters); } diff --git a/src/Abstractions/INavigationService.cs b/src/Abstractions/INavigationService.cs index 15cfb4a..3b7f89e 100644 --- a/src/Abstractions/INavigationService.cs +++ b/src/Abstractions/INavigationService.cs @@ -83,7 +83,6 @@ Task ResetStackAndPush(NavigationParameters navigationParameters) /// When within a , use this method to select a tab. /// /// Type of Page - /// A completed task - Task SelectTab() + void SelectTab() where T : Page; } diff --git a/src/Services/NavigationService.cs b/src/Services/NavigationService.cs index 32fdf88..e5de371 100644 --- a/src/Services/NavigationService.cs +++ b/src/Services/NavigationService.cs @@ -1,7 +1,9 @@ -namespace Burkus.Mvvm.Maui; +namespace Burkus.Mvvm.Maui; internal class NavigationService : INavigationService { + #region Core navigation methods + public async Task Push() where T : Page { var parameters = new NavigationParameters(); @@ -63,6 +65,10 @@ await HandleNavigation(async () => navigationParameters); } + #endregion Core navigation methods + + #region Advanced navigation methods + public async Task ReplaceTopPage() where T : Page { @@ -115,6 +121,10 @@ await HandleNavigation(async () => navigationParameters); } + #endregion Advanced navigation methods + + #region Internal implementation + private async Task HandleNavigation(Func navigationAction, NavigationParameters navigationParameters) where T : Page { @@ -143,7 +153,11 @@ private async Task HandleNavigation(Func navigationAction, NavigationPa } } - public async Task SelectTab() where T : Page + #endregion Internal implementation + + #region Tab navigation methods + + public void SelectTab() where T : Page { var tabbedPage = MauiPageUtility.GetTopPage() as TabbedPage; @@ -171,4 +185,6 @@ public async Task SelectTab() where T : Page } } } + + #endregion Tab navigation methods }