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] White Flash on iOS When Transitioning from Launch Screen to Application.Current.MainPage #8073

Open brminnick opened 4 years ago

brminnick commented 4 years ago

Description

On iOS, when the app transitions from the Launch Screen to Application.Current.MainPage (i.e. when LoadApplication(new App()) runs), the app flashes white.

I think I've narrowed it down to PlatformRenderer.ViewWillAppear where Xamarin.Forms sets View.BackgroundColor = UIColor.White: https://github.com/xamarin/Xamarin.Forms/blob/98b9f7d6bab9265c8ca0fd8e47e8899b85d7f609/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs#L85

If it is required to set View.BackgroundColor, these may be better options:

I've created a reproduction sample here: https://github.com/brminnick/DarkModeSplashScreen

Repro Video

Steps to Reproduce

  1. Download/Clone the reproduction sample: https://github.com/brminnick/DarkModeSplashScreen
  2. In Visual Studio, open DarkModeSplashScreen.sln
  3. In Visual Studio, set DarkModeSplashScreen.iOS as the Startup Project
  4. In Visual Studio, Build/Deploy DarkModeSplashScreen.iOS to an iOS 13 emulator or device
  5. Force-close the app
  6. On the iOS 13 emulator/device open the Settings app
  7. In the Settings app, select Developer
  8. In the Developer Settings enable Dark Appearance
  9. In Visual Studio, Build/Deploy DarkModeSplashScreen.iOS the same emulator/device
  10. While the app is launching, notice the white flash after the Launch Screen is dismissed

Expected Behavior

No white flash should happen when transitioning from the Launch Screen to Application.Current.MainPage.

Actual Behavior

No white flash should happen when transitioning from the Launch Screen to Application.Current.MainPage.

Basic Information

Screenshots

https://github.com/brminnick/Videos/blob/master/DarkModeSplashScreen/LaunchVideo.gif?raw=true

Reproduction Link

https://github.com/brminnick/DarkModeSplashScreen

Environment

=== Visual Studio Enterprise 2019 for Mac ===

Version 8.3.4 (build 8) Installation UUID: 80ff7ebc-b47d-4d51-98cc-e49b7b5e3b62 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)

Package version: 604000208

=== Mono Framework MDK ===

Runtime: Mono 6.4.0.208 (2019-06/07c23f2ca43) (64-bit) Package version: 604000208

=== NuGet ===

Version: 5.3.0.6192

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.0.100/Sdks SDK Versions: 3.0.100 3.0.100-rc1-014190 3.0.100-preview9-014004 3.0.100-preview8-013656 3.0.100-preview7-012821 3.0.100-preview6-012264 2.2.402 2.1.701 2.1.700 1.1.14 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 3.0.0 3.0.0-rc1-19456-20 3.0.0-preview9-19423-09 3.0.0-preview7-27912-14 3.0.0-preview6-27804-01 2.2.7 2.1.13 2.1.12 2.1.11 1.1.13 1.0.16

=== Xamarin.Profiler ===

Version: 1.6.12.29 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 11.1 (15405) Build 11A1027

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 13.4.0.2 (Visual Studio Enterprise) Hash: e37549bc Branch: xcode11.1 Build date: 2019-10-07 22:43:23-0400

=== Xamarin.Android ===

Version: 10.0.3.0 (Visual Studio Enterprise) Commit: xamarin-android/d16-3/4d45b41 Android SDK: /Users/bramin/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: None installed

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 29.0.3 SDK Build Tools Version: 28.0.3

Build Information: Mono: mono/mono/2019-06@5608fe0abb3 Java.Interop: xamarin/java.interop/d16-3@5836f58 LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94 LibZip: nih-at/libzip/rel-1-5-1@b95cf3fd ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.27.1@8212a2d Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/bramin/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 1.4.0.65 Hash: c33b107 Branch: remotes/origin/d16-3 Build date: 2019-10-08 23:36:20 UTC

=== Android Device Manager ===

Version: 1.2.0.116 Hash: d2b2af0 Branch: remotes/origin/d16-3 Build date: 2019-10-08 23:36:44 UTC

=== Xamarin Designer ===

Version: 16.3.0.247 Hash: 52eac1a9e Branch: remotes/origin/d16-3 Build date: 2019-10-03 23:04:28 UTC

=== Xamarin Inspector ===

Version: 1.4.3 Hash: db27525 Branch: 1.4-release Build date: Mon, 09 Jul 2018 21:20:18 GMT Client compatibility: 1

=== Build Information ===

Release ID: 803040008 Git revision: 8da5857bc3d33e5667cacaab3bd1ab55375ed3e3 Build date: 2019-10-14 18:26:13+00 Build branch: release-8.3 Xamarin extensions: 61c91e660a01512a3b8187c749fd3bccc75a2bf4

=== Operating System ===

Mac OS X 10.15.0 Darwin 19.0.0 Darwin Kernel Version 19.0.0 Wed Sep 25 20:18:50 PDT 2019 root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64

kingces95 commented 4 years ago

DarkModeSplashScreen-master.zip

kingces95 commented 4 years ago

I think I see it. On my sim the flash is really quick. A1DA352C-DE74-4206-A959-2C5162072BA5

brminnick commented 4 years ago

Yup, it’s pretty quick but certainly noticeable when using a black/dark Launch Screen.

You can see it in the current version of my app in the App Store too: https://apps.apple.com/us/app/punday/id1085414548

Jakar510 commented 4 years ago

It occurs for me on both Android and iOS.

After troubleshooting, I discovered it's an issue with the default colors when navigating-- something used before the page is rendered. this may be before the resource dictionaries are parsed as well. Unfortunately, I don't know enough about the low-level / backend code to know for sure.

The iOS code doesn't work correctly as I can't have await-ables in the App() which is needed to get the coloring correct when navigating. The App.OnStart() doesn't seem to work correctly: whatever the default is in your app, that will flash when navigation occurs, In other words, a default white background will flash before the page is rendered to dark mode. Setting the defaults (whatever colors for the background needed. i.e. App.Current.Resources = new DarkModeTheme() for dark pages) before the page is called (i.e. SomePage()) gives the correct results as it must be done before navigation occurs and the page is rendered.

see here for more details

I created a stackoverflow Post for this issue.

brminnick commented 4 years ago

@Jakar510 I took a look at your reproduction sample and I cannot replicate the white flash you're reporting on Android.

Your Android app doesn't have a splash screen and Android is using the default splash screen which is a white page.

I also sent you a pull request that fixes some compiler errors and runtime exceptions: https://github.com/Jakar510/FlickerTest/pull/1

Jakar510 commented 4 years ago

Thanks to brminick, we came up with a solution as below: add this to the App() constructor.

public App()
        {            
            # whatever else your app needs.

            if (Device.RuntimePlatform == Device.Android)
            {
                Theme systemThemeAsync = GetOperatingSystemThemeAsync().Result;
                InitializeComponent();
                MainPage = new NavigationPage(new MainPage(systemThemeAsync));
            }
            else
            {
                InitializeComponent();
                MainPage = new NavigationPage(new MainPage());
            }

        }

See https://github.com/Jakar510/FlickerTest for more details.