maui
maui copied to clipboard
NavigationPage does not close reliably
Description
I am facing an issue which causes a NavigationPage to "stick". Basically when i want to close the Page using Navigation.PopAsync, the same page is opened again. Another thing that can happen is that the previous page does pop up after a second tap on the back and going back from there or forward does not work properly anymore.
Something of note that may mess with the navigation is that i removed the AppShell. That is because in the original project the repro project is based on i couldn't figure out how to open a different page than the page declared in the AppShell.xaml depending on a few conditions.
Steps to Reproduce
- Clone my repro project.
- Tap the Button "Show an error".
- Use the Back button to go back to the previous page.
- Tap the Button "Do something" to go to the next page.
Going forward and back has worked so far.
- Tap the Button "Show an error".
- Use the back button to go back again.
- Tap the Button "Do something again" to go to the next page.
Going forward and back has worked again. The next page will automatically open an error page which you can't leave. Or you can leave that page but not the previous page. Anyway the navigation is broken now.
Link to public reproduction project repository
https://github.com/AlphaNERD-/MAUIPageNotClosingDemo
Version with bug
8.0.71 SR7.1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 14
Did you find any workaround?
No response
Relevant log output
No response
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Open similar issues:
- Shell backwards navigation problem by calling wrong OnAppearing/OnDisappearing (#21274), similarity score: 0.79
- NavigationPage shows title bar before navigating (#21134), similarity score: 0.79
Closed similar issues:
- NavigationPage breaks after some navigation forth and back (#20032), similarity score: 0.82
- Android NavigationPage in inconsistent state if Push/Pop operations are performed sometime after app deactivation (#16441), similarity score: 0.79
- Navigation stops working (#13695), similarity score: 0.78
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
I can repro this issue at android platform on the latest 17.11.0 Preview 7.0 (8.0.80 & 8.0.70) MAUIPageNotClosingDemo-main.zip
A few things here
-
You don't need to wrap every single page in a NavigationPage. You probably only need the root page to be wrapped into a root page
-
The reason that middle page is blank is most likely due to the fact that you're performing the push from inside a "Task". That's going to schedule that work off the dispatcher thread which is going to act in a somewhat undefined way.
-
If I change the code inside
OnAppearingto use theDipatcherit all operates in a much more expected way. Page2 is pushing Page3 and then Page3 now pushes the ErrorPage. So your navigation stack is "Page2/Page3/ErrorPage", pushing a page from appearing doesn't interrupt the other page from getting pushed. You would need to pop it before pushing it.
If I change Page3 to this
It all acts somewhat expected. All three pages get pushed onto the stack and then every time I click the back button OnAppearing fires on Page3 which then repushes the error page on the stack
Hi @AlphaNERD-. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.