From 42c6ed054ed474f46543d7085a5fadef29f5f9c2 Mon Sep 17 00:00:00 2001 From: b Date: Wed, 18 Nov 2026 23:17:44 +0100 Subject: [PATCH] fix(ios): read the system appearance before the window has a root view controller The launch event fires before the primary window gets its root view controller, and both Application.systemAppearance() and IOSNativeWindow.systemAppearance() returned null then. Apps that pick their theme in a launch handler got no appearance and rendered with empty colors. Fall back to the window and then the screen trait collection when there is no root view controller yet. Co-Authored-By: Claude Sonnet 5.5 --- packages/core/application/application.ios.ts | 7 ++++--- packages/core/native-window/native-window.ios.ts | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/core/application/application.ios.ts b/packages/core/application/application.ios.ts index 9fddbf1152..3910ae3a3c 100644 --- a/packages/core/application/application.ios.ts +++ b/packages/core/application/application.ios.ts @@ -1106,12 +1106,13 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication protected getSystemAppearance(): 'light' | 'dark' { // userInterfaceStyle is available on UITraitCollection since iOS 12. - if ((!__VISIONOS__ && SDK_VERSION <= 11) || !this.rootController) { + if (!__VISIONOS__ && SDK_VERSION <= 11) { return null; } - const userInterfaceStyle = this.rootController.traitCollection.userInterfaceStyle; - return this.getSystemAppearanceValue(userInterfaceStyle); + // the launch event fires before the window has a root view controller: the screen traits are enough then + const traits = this.rootController?.traitCollection ?? this.window?.traitCollection ?? UIScreen.mainScreen.traitCollection; + return this.getSystemAppearanceValue(traits.userInterfaceStyle); } private getSystemAppearanceValue(userInterfaceStyle: number): 'dark' | 'light' { diff --git a/packages/core/native-window/native-window.ios.ts b/packages/core/native-window/native-window.ios.ts index 360f808654..039db966db 100644 --- a/packages/core/native-window/native-window.ios.ts +++ b/packages/core/native-window/native-window.ios.ts @@ -141,11 +141,9 @@ export class IOSNativeWindow extends NativeWindow { if (!__VISIONOS__ && SDK_VERSION <= 11) { return null; } - const rootVC = this._window?.rootViewController; - if (!rootVC) { - return null; - } - return this._getSystemAppearanceValue(rootVC.traitCollection.userInterfaceStyle); + // the launch event fires before the window has a root view controller: the screen traits are enough then + const traits = this._window?.rootViewController?.traitCollection ?? this._window?.traitCollection ?? UIScreen.mainScreen.traitCollection; + return this._getSystemAppearanceValue(traits.userInterfaceStyle); } protected _getLayoutDirection(): CoreTypes.LayoutDirectionType | null {