diff --git a/React/CoreModules/RCTAppearance.h b/React/CoreModules/RCTAppearance.h index ece36942b7b..2644783e5d6 100644 --- a/React/CoreModules/RCTAppearance.h +++ b/React/CoreModules/RCTAppearance.h @@ -10,6 +10,8 @@ #import #import +RCT_EXTERN void RCTEnableAppearancePreference(BOOL enabled); + NSString *const RCTUserInterfaceStyleDidChangeNotification = @"RCTUserInterfaceStyleDidChangeNotification"; @interface RCTAppearance : RCTEventEmitter diff --git a/React/CoreModules/RCTAppearance.mm b/React/CoreModules/RCTAppearance.mm index 300a102068f..ad4233c6f6b 100644 --- a/React/CoreModules/RCTAppearance.mm +++ b/React/CoreModules/RCTAppearance.mm @@ -17,6 +17,11 @@ using namespace facebook::react; NSString *const RCTAppearanceColorSchemeLight = @"light"; NSString *const RCTAppearanceColorSchemeDark = @"dark"; +static BOOL sAppearancePreferenceEnabled = YES; +void RCTEnableAppearancePreference(BOOL enabled) { + sAppearancePreferenceEnabled = enabled; +} + static NSString *RCTColorSchemePreference(UITraitCollection *traitCollection) { #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 @@ -31,6 +36,11 @@ static NSString *RCTColorSchemePreference(UITraitCollection *traitCollection) }; }); + if (!sAppearancePreferenceEnabled) { + // Return the default if the app doesn't allow different color schemes. + return RCTAppearanceColorSchemeLight; + } + traitCollection = traitCollection ?: [UITraitCollection currentTraitCollection]; return appearances[@(traitCollection.userInterfaceStyle)] ?: RCTAppearanceColorSchemeLight; }