diff --git a/packages/react-native/React/CoreModules/RCTAppearance.mm b/packages/react-native/React/CoreModules/RCTAppearance.mm index 2930401fc98f6e..09fc70ca9797e7 100644 --- a/packages/react-native/React/CoreModules/RCTAppearance.mm +++ b/packages/react-native/React/CoreModules/RCTAppearance.mm @@ -36,6 +36,15 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride) return sColorSchemeOverride; } +static UITraitCollection *getKeyWindowTraitCollection() +{ + __block UITraitCollection *traitCollection = nil; + RCTExecuteOnMainQueue(^{ + traitCollection = RCTSharedApplication().delegate.window.traitCollection; + }); + return traitCollection; +} + NSString *RCTColorSchemePreference(UITraitCollection *traitCollection) { static NSDictionary *appearances; @@ -57,7 +66,7 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride) return RCTAppearanceColorSchemeLight; } - traitCollection = traitCollection ?: [UITraitCollection currentTraitCollection]; + traitCollection = traitCollection ?: getKeyWindowTraitCollection(); return appearances[@(traitCollection.userInterfaceStyle)] ?: RCTAppearanceColorSchemeLight; // Default to light on older OS version - same behavior as Android.