diff --git a/packages/react-native/React/CoreModules/RCTAppearance.mm b/packages/react-native/React/CoreModules/RCTAppearance.mm index 4f7350faad7f..3e416ee81c36 100644 --- a/packages/react-native/React/CoreModules/RCTAppearance.mm +++ b/packages/react-native/React/CoreModules/RCTAppearance.mm @@ -19,6 +19,8 @@ NSString *const RCTAppearanceColorSchemeLight = @"light"; NSString *const RCTAppearanceColorSchemeDark = @"dark"; +static BOOL sIsAppearancePreferenceSet = NO; + static BOOL sAppearancePreferenceEnabled = YES; void RCTEnableAppearancePreference(BOOL enabled) { @@ -62,6 +64,12 @@ void RCTUseKeyWindowForSystemStyle(BOOL useMainScreen) // Return the default if the app doesn't allow different color schemes. return RCTAppearanceColorSchemeLight; } + + if (appearances[@(traitCollection.userInterfaceStyle)]){ + sIsAppearancePreferenceSet = YES; + return appearances[@(traitCollection.userInterfaceStyle)]; + } + UIUserInterfaceStyle systemStyle = sUseKeyWindowForSystemStyle ? RCTKeyWindow().traitCollection.userInterfaceStyle : traitCollection.userInterfaceStyle; return appearances[@(systemStyle)] ?: RCTAppearanceColorSchemeLight; @@ -116,6 +124,10 @@ - (dispatch_queue_t)methodQueue RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getColorScheme) { + if (!sIsAppearancePreferenceSet) { + UITraitCollection *traitCollection = RCTKeyWindow().traitCollection; + _currentColorScheme = RCTColorSchemePreference(traitCollection); + } return _currentColorScheme; }