You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some of our users managed to accidentally close the app by swiping back on the main page on Android.
To prevent this, I tried to implement the IConfirmNavigationAsync interface in our MainPageViewModel.
Unfortunately, this method never gets called. Instead, I see an exception in our logs:
Navigation failed
Prism.Navigation.NavigationException: Cannot Pop Application MainPage
at Prism.Navigation.PageNavigationService.GoBackAsync(INavigationParameters parameters)
Implement the IConfirmNavigationAsync interface and disallow navigating back on the MainPageViewModel
Run the app and swipe back on the main page
Expected result: The IConfirmNavigationAsync.CanNavigateAsync method gets called and I can prevent that the app gets closed.
Actual result: The IConfirmNavigationAsync.CanNavigateAsync method gets not called and the app gets closed.
Platform with bug
.NET MAUI
Affected platforms
Android
Did you find any workaround?
As a workaround I override the OnBackButtonPressed method of the FlyoutPage:
protectedoverrideboolOnBackButtonPressed(){// The FlyoutPage is the container and OnBackButtonPressed gets also called when navigating back in the details navigation pageif(Detail is NavigationPage navPage &&(navPage.Navigation.NavigationStack.Count >1|| navPage.Navigation.ModalStack.Count >1)){returnbase.OnBackButtonPressed();}returntrue;}
Relevant log output
No response
The text was updated successfully, but these errors were encountered:
Description
Same as #2914 but with a sample attached.
Some of our users managed to accidentally close the app by swiping back on the main page on Android.
To prevent this, I tried to implement the
IConfirmNavigationAsync
interface in ourMainPageViewModel
.Unfortunately, this method never gets called. Instead, I see an exception in our logs:
We are using a
FlyoutPage
as main page.I created a sample here: https://github.com/berhir/Prism/tree/PrismFlyoutCanNavigateIssue/PrismFlyoutCanNavigate
I tested it on Android and the
CanNavigateAsync
method of theMainViewModel
never gets called.See https://github.com/berhir/Prism/blob/PrismFlyoutCanNavigateIssue/PrismFlyoutCanNavigate/MainViewModel.cs
You can test my workaround by uncommenting the code in this file: https://github.com/berhir/Prism/blob/PrismFlyoutCanNavigateIssue/PrismFlyoutCanNavigate/MainPage.xaml.cs
Steps to Reproduce
IConfirmNavigationAsync
interface and disallow navigating back on theMainPageViewModel
Expected result: The
IConfirmNavigationAsync.CanNavigateAsync
method gets called and I can prevent that the app gets closed.Actual result: The
IConfirmNavigationAsync.CanNavigateAsync
method gets not called and the app gets closed.Platform with bug
.NET MAUI
Affected platforms
Android
Did you find any workaround?
As a workaround I override the
OnBackButtonPressed
method of theFlyoutPage
:Relevant log output
No response
The text was updated successfully, but these errors were encountered: