xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] Replacing FlyoutPage.Detail does not invoke the Application.PageDisappearing event #15752

Open blablubbabc opened 1 year ago

blablubbabc commented 1 year ago

Description

I don't have the time right now to prepare a minimal reproduction sample or fill in all the details of the issue template. I tested this on Android.

Steps to Reproduce

  1. Register an event handler for the app.PageDisappearing event: Log event.
  2. App layout: app.MainPage = NavigationPage(FlyoutPage)
  3. Set flyoutPage.Detail = NavigationPage(page1) (In my particular case, the detail pages are nested in another Navigation page, but this should not matter regarding reproducing the issue)
  4. Set flyoutPage.Detail = NavigationPage(page2)
  5. The page1 has its OnDisappearing overridden: Calls base and logs call.

Expected Behavior

Observe both the page's own OnDisappearing call, as well as the app's PageDisappearing event.

Actual Behavior

Only observe the page's own OnDisappearing call.

Analysis

My guess is that the Detail page is no longer a child of the FlyoutPage at the time its SendDisappearing is invoked: Setting Detail removes the old page from the parents (https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Core/FlyoutPage.cs#L46). Only afterwards, the Android FlyoutPage renderer is notified, which updates the platform view (https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.Android/AppCompat/FlyoutPageRenderer.cs#L481), which eventually results in the old page's SendDisappearing to be invoked.

SendDisappearing can call the page's OnDisappearing, but is not able to find the application on which to call the PageDisappearing event: https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Core/Page.cs#L478