Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell backwards navigation problem by calling wrong OnAppearing/OnDisappearing #21274

Open
nicop85 opened this issue Mar 18, 2024 · 1 comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@nicop85
Copy link

nicop85 commented Mar 18, 2024

Description

I've found an issue where if you have stacked at least two pages by using Shell.GoToAsync, when you navigate back to the MainPage, it will trigger the OnAppearing of a previous page before the OnDisappearing of the current.

In the example code that is pointed out below, you will find a simple project where you have a MainPage and three other sub pages (Page1, Page2 and Page3).

  • On the OnAppearing of the MainPage, it adds a ToolbarItem to go to Page1. On the OnDisappearing of the MainPage it clears the ToolbarItems.
  • On the OnAppearing of the Page1, it adds a ToolbarItem to go to Page2. On the OnDisappearing of the Page1 it clears the ToolbarItems.
  • On the OnAppearing of the Page2, it adds a ToolbarItem to go to Page3. On the OnDisappearing of the Page2 it clears the ToolbarItems.
  • On the OnAppearing of the Page3, it does nothing. On the OnDisappearing of the Page3 it does nothing.

So every time you navigate to a page, it will have a toolbar item to go to the next one until you reach the last one where you can only go backwards.

The problem is that when you reach the last page (Page3) and then press the back button of the Shell, it goes to Page2 and shows the right toolbar item to go to Page3. But if you press the back button again to go to Page1, you will see the Page1 but no ToolbarItem is beeing displayed (it should show the toolbar item to go to Page2). While debugging it, I figured out that when you press the back button it is triggering the following:

  1. The OnAppearing method in Page1, but having Shell.Current.CurrentPage == "Page2"
  2. The OnDisappearing method in Page2, having Shell.Current.CurrentPage == "Page2"

It should have triggers first the OnDisappearing of Page2 and then de OnAppearing of Page1 with the CurrentPage already set to the Page1.

Video:
https://github.com/dotnet/maui/assets/2288412/8f1e8506-e45e-463f-a964-c18ad6b06c35

Steps to Reproduce

  1. Clone the provided repo
  2. Execute the app (verified on Android and Windows)
  3. Navigate to the last page using the top toolbar items
  4. Start navigating back
  5. When you reach Page1, no toolbar item will be displayed

Link to public reproduction project repository

https://github.com/nicop85/TestBackwardsNavigation.git

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Windows 10.0.17763.0, Android 11 and up

Did you find any workaround?

No response

Relevant log output

No response

@nicop85 nicop85 added the t/bug Something isn't working label Mar 18, 2024
@PureWeen PureWeen added area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events area-controls-shell Shell Navigation, Routes, Tabs, Flyout labels Mar 18, 2024
@PureWeen PureWeen added this to the Backlog milestone Mar 18, 2024
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 10, 2024
@XamlTest
Copy link

Verified on VS 17.10.0 Preview 2.0(8.0.20). Repro on Windows 11 and Android 14.0-API34 with below Project:
TestBackwardsNavigation.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants