Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] Navigation PopToRootAsync() then PushAsync() of Current Page Doesn't Display Page Content

Open ncosentino opened this issue 4 years ago • 8 comments

Description

I have an app that is setup to be Master Detail + Navigation Pages.

  • MasterDetail -> MainPage.xaml (it's of type MasterDetail)
  • MasterDetail.Master ->MenuPage.xaml (it's of type ContentPage)
  • MasterDetail.Detail ->HomePage.xaml (it's of type ContentPage but wrapped in a NavigationPage before being assigned to the Detail page property)

Navigation in general works exactly how I'd like with my swipe out menu, hamburger menu icon vs back button... It's all great. However, I run into some weird behavior when I try to reset my navigation stack and then push a page that was already somewhere in the navigation stack.

Steps to Reproduce

  1. Launch the application. HomePage is showing.
  2. Open the Menu
  3. Select Page1 (equivalent to Detail.Navigation.PopToRootAsync() followed by Detail.Navigation.PushAsync(page1))
  4. Use a button on Page1 to navigate to Page2 (equivalent to Detail.Navigation.PushAsync(page2))
  5. Use a button Page2 to reset navigation back to Page1 (equivalent to Detail.Navigation.PopToRootAsync() followed by Detail.Navigation.PushAsync(page1))
  6. I notice that Page1.OnAppearing() fires twice in a row (AFTER step 5)
  7. The title of the page is displayed (so I know it's on Page1) but the content below is entirely blank and shows a white background

Expected Behavior

I should be able to navigate back to Page1 after everything has been popped out of the navigation stack, regardless of whether it was there before or not.

Actual Behavior

Page1 is displayed at the end, but there is no content on the page.

Basic Information

  • Version with issue: Xamarin.Forms 4.6.0.800
  • Last known good version: EDIT: I have determine that v4.4.0.991265 does work.
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:
    • iOS: Deployment Target 12.0
    • Android: Android 9, API 28
    • UWP: Not using.
  • Android Support Library Version:
  • Nuget Packages:
    • Autofac, Version=5.1.2
    • Humanizer, Version=2.7.9
    • MLToolkit.Forms.SwipeCardView, Version=2.1.0
    • Rg.Plugins.Popup, Version=2.0.0.2
    • System.ComponentModel.Annotations, Version=4.7.0
    • System.Linq.Async, Version=4.1.1
    • Xam.Plugins.Forms.ImageCircle, Version=3.0.0.5
    • Xamarin.Auth, Version=1.7.0
    • Xamarin.Forms, Version=4.6.0.800
    • Xamarin.Essentials, Version=1.5.3.2
    • Newtonsoft.Json, Version=12.0.3
    • Xamarin.Forms.InputKit, Version=3.2.2
    • Xamarin.Forms.Maps, Version=4.6.0.800
  • Affected Devices:

Screenshots

First I slide out the menu (The pages just to test this with are called Nav Fun 1 and Nav Fun 2) Screenshot_20200526-141802

I select Nav Fun 1 from the menu and it shows properly. Screenshot_20200526-141811

I select Forward to Nav Fun 2 and then it shows properly. Screenshot_20200526-141818

I select Reset to Nav Fun 1 (which to does the PopToRoot call and then Push(NavFun1) and this is the result. Screenshot_20200526-141826

Reproduction Link

Workaround

Only workaround I can find is just to try and prevent this entirely... Which isn't great. It means that if I have push notifications that I want to bring my user to part of the application and they happen to already have that page somewhere on their navigation stack, when I pop to root and then push the new page, it'll have this funny behavior of showing a white screen.

ncosentino avatar May 26 '20 18:05 ncosentino

Can you please attach a small project that demonstrates this issue? Thanks!

samhouts avatar May 26 '20 22:05 samhouts

@samhouts will do!

I was panicking because I recreated a project and I wasn't able to reproduce... But I've determined that it's totally working on the default I have setup when making a new project (v4.4.0.991265) and broken on v4.6.0.800.

Will package it up and respond in just a moment. I'll provide some instructions as well because well... I just hacked up the sample project and it's kind of ridiculous haha

ncosentino avatar May 27 '20 00:05 ncosentino

Issue10856.zip

Repro steps with this project:

  • Launch the app
  • Open the menu
  • Go to "About"
  • About should load properly
  • Press the button called "Navigate to the other page"
  • It should navigate to the "Browse" page properly
  • Slide out the menu by dragging from the edge of the phone
  • Select either of the menu items (Browse or About)
  • The page will semi load... You'll get the title in the title bar but the actual content will not be present (just a white background)

Full disclosure, I didn't try running this on the iOS device I have, but this setup does reproduce now on the android phone that I have.

ncosentino avatar May 27 '20 01:05 ncosentino

I think this bug is related with AndroidX packages...

I`m having exactly the same issue related... Just solved when I downgraded my Xamarin.Form to 4.6.0.726 AND install some AndroidX packages:

Xamarin.Android.Support.Compat (28.0.0) - PancakeView related Xamarin.AndroidX.Legacy.Support.V4 (1.0.0) Xamarin.AndroidX.Lifecycle.LiveData (2.2.0)

Also, I have the Xamarin.AndroidX.Migration (1.0.6 AND 3x 1.0.0-preview03 in my .csproj) and Xamarin.AndroidX.Core (3x on my .csproj), I don't know why...

BUT, it's working... LoL...

I'll try remove those duplicates...

balivo avatar Jun 01 '20 16:06 balivo

I'm having this issue as well, but in my case, the page isn't displayed at all.

Using Shell layout, compiled on Android 10, Xamarin.Forms v4.6.0.847.

Jakar510 avatar Jun 09 '20 19:06 Jakar510

I found a workaround for now.

  1. add the page data to the root page (whatever you need to perform the navigation and display properly)
  2. call: await page.Navigation.PopToRootAsync().ConfigureAwait(true);
  3. override the OnAppearing() method of the root page, adding await Navigation.PushAsync(new Page(PageData)).ConfigureAwait(true);

It works as this occurs on a completely different thread/Task, but does show the original page briefly which is not ideal but I haven't found any other way to get around it for now.

Jakar510 avatar Jun 15 '20 22:06 Jakar510

any update?

Jakar510 avatar Jul 10 '20 01:07 Jakar510

Anyone else landing on the item looking for a solution, can try passing the value true to the PopToRootAsync function.

jameswestgate avatar Sep 13 '22 15:09 jameswestgate