xamarin / Xamarin.Forms

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

[Bug] After PopModalAsync will not call OnAppearing (iOS) #13258

Open oleksandrtretiak opened 3 years ago

oleksandrtretiak commented 3 years ago

Description

Steps to Reproduce

  1. Open Page1
  2. Push modal Page2
  3. PopModalAsync

Expected Behavior

Page1 Call OnAppearing

Actual Behavior

Nothing

Basic Information

Environment

Screenshots

Reproduction Link

Workaround

rachelkang commented 3 years ago

Hi, @oleksandrtretiak - thanks for submitting this issue! I tried reproducing what you described, but unfortunately wasn't able to. I see the calls to OnAppearing made on both the first page and modal page when running on 5.0pre6. Would you mind sharing your project / a sample project or modifying this sample project to reproduce the behavior you're experiencing? Thanks :)

oleksandrtretiak commented 3 years ago

Hi, @rachelkang ! Sorry that I gave you not enough details. Use Navigation.PushModalAsync(new NavigationPage(new ModalPage()) { BackgroundColor = Color.Red });

The problem with BackgroundColor of NavigationPage;

Or download the updated project.

beeradmoore commented 3 years ago

Came to report the same issue, did not realise the issue is setting BackgroundColor. I'll go try fix that as a workaround for me.

As for this issue, I was able to replicate the issue by changing the Push_Modal method from the original sample to look like so

        void Push_Modal(object sender, EventArgs e)
        {
            Navigation.PushModalAsync(new ModalPage()
            {
                BackgroundColor = Color.Red
            });
        }

Main difference from @oleksandrtretiak comment above is that you don't need to use NavigationPage in the PushModal.

I have updated the sample with a few changes.

Issue13258 - beeradmoore.zip

EDIT 1:

Looking into the XF source code ViewDidAppear, ViewWillAppear, ViewDidDisappear in Xamarin.Forms.Platform.iOS.NavigationRenderer do not get called if we called PushModal with new page with the BackgroundColor property set.

I have made a repo issue in the XF control gallery on my own fork here.

EDIT 2: Using Background instead of BackgroundColor will not produce the same issue. This may be a workaround for some, but I still can't see the underlying issue. In all my years of using Xamarin.iOS I don't believe I've come across a situation where ViewDidAppear would not fire, however there are plenty of results on google of people having the same issue even when not using Xamarin.

PaulMercer-SDS commented 3 years ago

This is an issue for us too. From a ContentPage we push a modal page which changes some state in the app. When the modal page is popped, we are checking that state in the OnAppearing event of the original page. This was working up to XF 5.0 pre2, but from pre3 or pre4 the event is no longer being fired.

beeradmoore commented 3 years ago

I tested what @PaulMercer-SDS mentioned

5.0.0.1558-pre3 works 5.0.0.1709-pre4 broken 5.0.0.1905 broken (though I didn't expect this to contain a fix)

I had a real quick browse of pre4 and what had changed and nothing stood out immediately.

Glomby commented 3 years ago

I ran into the same issue after going from forms 4.5 to latest 5.0.0.1931

On iOS the OnAppearing does not fire. On Android it still does. In my case this breaks the App quite a bit.

DawidBester commented 3 years ago

Any workaround, or a time frame for a fix for this issue?

I've upgraded from XF 4.8 to 5.0.0.2012, and per this issue description, the OnAppearing event no longer fires after PopModalAsync on the iOS version of my app. Android works as expected.

DawidBester commented 3 years ago

I reran tests to see what needs to be done to ship my app, and will need to roll back to release 4.8.0.1821.

Tests done: Downgrade from 5.0.0.2012 to 5.0.0.1874; app broken Downgrade to 5.0.0.1558-pre3; app works as expected Upgrade to 5.0.0.1709-pre4; app broken Downgrade to 4.8.0.1821; app works as expected

beeradmoore commented 3 years ago

@DawidBester , a workaround for now is if you don't set the BackgroundColor of the new page issue won't occur.

I went and swapped all references of BackgroundColor on my content pages with Background and I feel yuck for doing so. But at least my app works as expected now 🤷‍♂️

DawidBester commented 3 years ago

@beeradmoore thanks!

I've tested and changing BackgroundColor to Background on the ContentPage works using 5.0.0.2012.

Now to go through the app and change all references. Definitely not ideal, but better than downgrading to 4.8.0.1821.

Henryegal commented 3 years ago

Hello there, I have this same issue possibly, but removing the "BackgroundColor" did not work. This is IOS only with latest xamarin. I do not want to downgrade. Is there any other messages like OnAppearing that you may have used instead?

DawidBester commented 3 years ago

@Henryegal I changed BackgroundColor to Background as I still needed to set a background color for the page, and this was the only change I made.

I did not test just removing BackgroundColor and then not setting a Background for the page.

Henryegal commented 3 years ago

@DawidBester Thanks for the info! I did change BackgroundColor="LightBlue" to just Background="LightBlue" And that did not work for me. I am in the process of changing everything I had done in OnAppearing to using the MessageCenter right after I PopModalAsync.

Very painful! Thanks again.

mike242529 commented 3 years ago

I removed the BackgroundColor assignment completely from the modal page's ContentPage xaml, so there was no assigned BackgroundColor at the page level. Then down inside the xaml page Content's first visual element that would show a background color (ListView) I added the same BackgroundColor assignment, and that worked for me as my workaround - to keep the background color and get around this strange unfortunate bug. (Xamarin.Forms 5.0.0.2012)

Thanks to everyone who left comments above - it has saved my day today.

rd09 commented 3 years ago

I had the same issue when pushing a modal from a contentpage then closing it would not call the OnAppearing method, but I was able to use the workaround that was mentioned here of using Background instead of BackgroundColor for the modal page.

Thank you guys for the workaround!!!

hydnar commented 3 years ago

We were having the same issue where, on iOS, popping a modal page did not call OnAppearing() on the page that is now visible. Android worked fine. We're setting the BackgroundColor on the modal page to white. We were not wrapping the modal page with a navigation page.

Rather than change from BackgroundColor to Background, instead we push the modal page wrapped in a navigation page, and have added the following attribute on our modal page: NavigationPage.HasNavigationBar="false"

That seems to solve the problem, and doesn't require using the Background workaround, and the appaerance of the page seems consistent with what we had before.

Henryegal commented 3 years ago

Hi there, Great thanks for the info. I will look into this. I had to rework this and not use OnAppearing as I was rushed to get it in the store. Thanks!

Henry Egal Software Developer Horizon Information Systems, Inc. 435 Napoleon St. Johnstown, PA 15901https://www.bing.com/maps?q=Horizon+Information+Systems&FORM=HDRSC4 | • (814) 535-7810 @.***D73490.809C9780]https://www.horizon-is.com/ [Text Description automatically generated]https://compliancy-group.com/

From: hydnar @.> Sent: Sunday, April 18, 2021 8:18 PM To: xamarin/Xamarin.Forms @.> Cc: Henry Egal @.>; Mention @.> Subject: Re: [xamarin/Xamarin.Forms] [Bug] After PopModalAsync will not call OnAppearing (iOS) (#13258)

We were having the same issue where, on iOS, popping a modal page did not call OnAppearing() on the page that is now visible. Android worked fine. We're setting the BackgroundColor on the modal page to white. We were not wrapping the modal page with a navigation page.

Rather than change from BackgroundColor to Background, instead we push the modal page wrapped in a navigation page, and have added the following attribute on our modal page: NavigationPage.HasNavigationBar="false"

That seems to solve the problem, and doesn't require using the Background workaround, and the appaerance of the page seems consistent with what we had before.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/xamarin/Xamarin.Forms/issues/13258#issuecomment-822093692, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOT6W5IKSTFZSPTA2MICY7LTJNZD3ANCNFSM4VPKVB6Q.

robsoft commented 3 years ago

Having the same problem here since we started 'themeing' our XF app. On iOS we don't see the underlying form's OnAppearing firing again when a modal dialog is popped. If we prevent the app from changing the BackgroundColor property again, it all works as it's supposed to.

pierom99 commented 3 years ago

I have the same problem, do you have a solution time?

KonstantinKellermann commented 3 years ago

We are facing the same issue. I've updatet Xamarin.Forms to the newest version 5.0.0.2125, unfortunatly it is still there.

ricavir11 commented 3 years ago

Did you plan to release a fix soon ?

ricavir11 commented 3 years ago

I tried the differents workarounds mentioned (BackgroudColor and wrapped NavigationPage) but none of them worked. I don't want to roll back to XF 4.8, so I'm stucked waiting for a fix :/

CNouws commented 3 years ago

We are facing the same issue. What is the current status of this?

mbastiaans commented 2 years ago

At this moment, we are using a workaround with page Disappearing.

if (Device.RuntimePlatform.Equals("iOS")) commentPage.Disappearing += async (sender, e) => await something();

This works fine for now, but is there by chance any proper fix in Xamarin.Forms that OnAppearing is triggered the right way?

mikeirvingweb commented 2 years ago

we're having this problem in an app today, on one particular page

I have found a workaround by overriding ModalPopped in the calling page, and then after checking if the device is iOS, I then do some of the functionality that should be done in the Appearing method.

wagenheimer commented 2 years ago

+1 with this issue. I will try the workarounds proposed here.

beeradmoore commented 2 years ago

On the bright side, I re-implemented my broken project from above in MAUI and the issue is fixed over there.

udde commented 2 years ago

Hello?! Two years later this still dosnt work? @xamarin-release-manager I am using PopModal() and OnAppearing() is beeing called on Android but not on iOS. I have the latest version of Xamarin, Visual Studio and Xcode.