iOS Allow disabling color scheme preference

Summary:
Some apps may need to disable the automatic dark mode color scheme assignment. This provides such kill switch.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D18088313

fbshipit-source-id: 75abf34e92f8a4a637daa26135adf85965cb9df5
This commit is contained in:
Kevin Gozali
2019-10-23 15:52:45 -07:00
committed by Facebook Github Bot
parent 85ac9cf6c7
commit 25d94ff34d
2 changed files with 12 additions and 0 deletions
+2
View File
@@ -10,6 +10,8 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
RCT_EXTERN void RCTEnableAppearancePreference(BOOL enabled);
NSString *const RCTUserInterfaceStyleDidChangeNotification = @"RCTUserInterfaceStyleDidChangeNotification";
@interface RCTAppearance : RCTEventEmitter <RCTBridgeModule>
+10
View File
@@ -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;
}