Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
GoToSection fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vniehues committed May 11, 2022
1 parent ec94cea commit 0944376
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions samples/mavvmApp/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewmodels="clr-namespace:mavvmApp.ViewModels" xmlns:mavvm="clr-namespace:mavvm;assembly=mavvm"

x:Class="mavvmApp.AppShell">
<ShellItem>
<ShellItem Route="start">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:MainPageViewModel}">
</mavvm:MavvmShellContent>
</ShellItem>
<TabBar>
<TabBar Route="main">
<Tab Title="Second" Route="firstTab">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:SecondPageViewModel}">
<mavvm:MavvmShellContent Title="MainPageTitle" ViewModel="{x:Type viewmodels:SecondPageViewModel}">
</mavvm:MavvmShellContent>
</Tab>
<Tab Title="Second 2" Route="secondTab">
Expand Down
2 changes: 1 addition & 1 deletion samples/mavvmApp/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void CountUp()

async void Navigate()
{
await BaseMethods.GoToViewModel<SecondPageViewModel>(false, new NavigationParameters{ { "countParam", Count } });
await BaseMethods.GoToSection("main", new NavigationParameters{ { "countParam", Count } });
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/mavvm/Navigation/BaseMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ public static async Task GoToSection(string sectionRoute, NavigationParameters p
}
else
{
await Shell.Current.GoToAsync(path, animate, parameters);
await Shell.Current.GoToAsync(path, false, parameters);

if ((Shell.Current?.CurrentItem?.CurrentItem as IShellSectionController)?.PresentedPage.BindingContext is INavigateBackToAware vm)
//HACK: Shell doesn'T immediately know about PresentedPage.
await Task.Delay(50);

if ((Shell.Current?.CurrentItem?.CurrentItem as IShellSectionController)?.PresentedPage?.BindingContext is INavigateToAware vmTo)
{
vm.NavigatedBackTo(parameters);
vmTo.NavigatedTo(parameters);
}

}
}

Expand Down

0 comments on commit 0944376

Please sign in to comment.