mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
85ac9cf6c7
commit
25d94ff34d
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user