Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

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

Open
oleksandrtretiak opened this issue Dec 31, 2020 · 28 comments
Open

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

oleksandrtretiak opened this issue Dec 31, 2020 · 28 comments

Comments

@oleksandrtretiak
Copy link

oleksandrtretiak commented Dec 31, 2020

Description

Steps to Reproduce

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

Expected Behavior

Page1 Call OnAppearing

Actual Behavior

Nothing

Basic Information

  • Version with issue: 5 pre6 ~
  • Last known good version: 4.8.1451
  • Platform Target Frameworks:
    • iOS: iOS, 14.3
  • NuGet Packages:
  • Affected Devices:

Environment

Screenshots

Reproduction Link

Workaround

@oleksandrtretiak oleksandrtretiak added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 31, 2020
@samhouts samhouts added this to New in Triage Dec 31, 2020
@rachelkang
Copy link
Contributor

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 :)

@rachelkang rachelkang added s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Jan 6, 2021
@rachelkang rachelkang moved this from New to Needs Info in Triage Jan 6, 2021
@oleksandrtretiak
Copy link
Author

oleksandrtretiak commented Jan 11, 2021

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
Copy link
Contributor

beeradmoore commented Jan 15, 2021

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.

  • Updated to Xamarin.Forms 5.0.0.1874
  • Added comments into MainPage.xaml.cs and ModalPage.xaml.cs to show what to comment in/out to make the events break
  • Stopped breakpointing and used System.Diagnostics.Debug.WriteLine to show output instead
  • Added OnDissapearing events to show they are not firing as well.
  • Changed Android SDK down to Android 10 (from Android 11, as I don't have SDK 30 installed) to confirm its still only an iOS issue.

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.

beeradmoore added a commit to beeradmoore/Xamarin.Forms that referenced this issue Jan 18, 2021
@Redth Redth removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Jan 21, 2021
@PaulMercer-SDS
Copy link

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.

@PureWeen PureWeen moved this from Needs Info to New in Triage Jan 22, 2021
@beeradmoore
Copy link
Contributor

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
Copy link

Glomby commented Jan 29, 2021

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.

@rachelkang rachelkang added 5.0.0 Regression on 5.0.0 e/3 🕒 3 m/high impact ⬛ and removed s/unverified New report that has yet to be verified labels Feb 2, 2021
@rachelkang rachelkang moved this from New to Ready For Work in Triage Feb 2, 2021
@DawidBester
Copy link

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
Copy link

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
Copy link
Contributor

@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
Copy link

@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
Copy link

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
Copy link

@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
Copy link

@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
Copy link

mike242529 commented Mar 25, 2021

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
Copy link

rd09 commented Apr 6, 2021

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
Copy link

hydnar commented Apr 19, 2021

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
Copy link

Henryegal commented Apr 19, 2021 via email

@robsoft
Copy link

robsoft commented May 22, 2021

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
Copy link

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

@KonstantinKellermann
Copy link

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
Copy link

Did you plan to release a fix soon ?

@ricavir11
Copy link

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
Copy link

CNouws commented Oct 28, 2021

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

@mbastiaans
Copy link

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
Copy link

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
Copy link

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

@beeradmoore
Copy link
Contributor

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

@udde
Copy link

udde commented May 30, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Triage
  
Ready For Work
Development

No branches or pull requests