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 {