maui icon indicating copy to clipboard operation
maui copied to clipboard

GoToAsync returns user to desired page but previous page's OnAppearing() is triggered

Open d-harding opened this issue 7 months ago • 2 comments

Description

When navigating pages with GoToAsync() in Shell, changing page hierarchy will result in OnAppearing() being called on a page that is not in the target navigation url/stack.

Steps to Reproduce

  1. Run app on Android (or iOS) (current: //MainPage)
  2. Click Go to Page 1 (current: //MainPage/Page1)
  3. Click Go to Page 2 (current: //MainPage/Page1/Page2)
  4. Click Go to SubMainPage (current: //MainPage/SubMainPage)
  5. Open Flyout or Command and click Return to MainPage (current: //MainPage)

When Return to MainPage is clicked, the command is executing the following await Shell.Current.GoToAsync($"//{nameof(MainPage)}");. This should return the user directly to the page based on the URL, however, OnAppearing will be triggered for Page2, which is unwanted and not desired.

Routes for MainPage and SubMainPage are defined in AppShell.xaml, where Page1 and Page2 are using RegisterRoute in AppShell.xaml.cs as to only show Back button.

Link to public reproduction project repository

https://github.com/d-harding/maui-pageflow

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

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

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

d-harding avatar Jan 24 '24 15:01 d-harding

Possibly related to this issue (same root cause?) there are already known issues with OnAppearing() and IsPresented not running at the correct times (in this case with a Flyout menu, with no Shell being used). See https://github.com/dotnet/maui/issues/15767

SmartmanApps avatar Jan 24 '24 23:01 SmartmanApps

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Jan 26 '24 15:01 ghost

Verified this on VS 17.10.0 Preview 1.0(8.0.6). Repro on Windows 11, Android 14.0-API34, iOS 17.2 and MacCatalyst with below Project: maui-pageflow.zip

XamlTest avatar Mar 07 '24 07:03 XamlTest