xamarin / Xamarin.Forms

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

[Bug] Forms 4.0 - change Application.Current.MainPage = freeze on iOS #6244

Closed DeerSteak closed 5 years ago

DeerSteak commented 5 years ago

Description

When changing Application.Current.MainPage on iOS using a button event on another page, the screen goes white and never displays the new page. The app does not crash, it just freezes. This previously happened in #4156 on Forms 3.3 and 3.4, but was fixed in 3.5 and 3.6.

Steps to Reproduce

  1. Create a new Project with Forms 4.0 + iOS
  2. Add a new SecondPage.XAML
  3. In App.xaml.cs, change the app's MainPage to SecondPage.XAML (just to verify its working)
  4. To the SecondPage add a button 'Click Me'. In the button handler add the following code

var myApp = (App)Xamarin.Forms.Application.Current; myApp.MainPage = new MainPage();

Run the iOS app, click the button 'Click Me'. Wait for few seconds and it will freeze.

Expected Behavior

That the SecondPage would be displayed

Actual Behavior

App freezes on iOS

Basic Information

Screenshots

Reproduction Link

samhouts commented 5 years ago

Issue6244.zip

@DeerSteak I was unable to reproduce this issue. I am able to swap pages rapidly, no freezing. Can you please take a look at the attached project and see if you experience the problem? If not, can you adjust it such that it demonstrates the behavior? Thanks!

DeerSteak commented 5 years ago

Yes, I will do that tonight. Thanks!

DeerSteak commented 5 years ago

@samhouts apparently I have misidentified the cause. I still have an issue with 4.0.0 that doesn't exist in 3.6.0 but it's not setting the main page. I'll continue to work on isolating it. Canceling this for now. Sorry for the trouble.

DeerSteak commented 5 years ago

Was able to trace it down to a NuGet package, and created a ticket with a sample app for that project. It only happened on Forms 4.0, but it required an update for that project instead. not Forms. My apologies.

sha256x commented 5 years ago

I'm also facing this exact issue, but cannot pin point a specific nugget package to be the problem. @DeerSteak, what package caused this problem for you?

edit: This happens on Xamarin.forms 4.1.0.618606

DeerSteak commented 5 years ago

@sha256x for me it was Plugin.SegmentedControl.Netstandard. I reported the bug and created a sample for the project maintainers and they fixed it in like 2 days. So if you have the latest version of that, it shouldn't be the cause.

sha256x commented 5 years ago

@DeerSteak, I don't have that installed :/ I still get the crash.

andyhoyle commented 5 years ago

Was LiveXAML for us

DeerSteak commented 5 years ago

I also had to fix it on some custom controls I wrote myself. Basically the page disappearing causes the control to fire OnElementChanged(), and apparently it never used to do that. I had to go through my custom controls and set anything that referenced a native control in the iOS and Android projects to include null checks for this.Control everywhere.