Add RCTOverrideAppearancePreference to iOS Appearance module
Summary: In order to enable more fine-grained control of theming in brownfield apps, this adds RCTOverrideAppearancePreference to RCTAppearance. ## Changelog: [iOS] [Added] - Adds RCTOverrideAppearancePreference to the iOS Appearance module Reviewed By: sammy-SC Differential Revision: D19187657 fbshipit-source-id: 52783c497d32d36af2523fce6f040d6cfb5aac3c
This commit is contained in:
Родитель
d43059d0b8
Коммит
fa65b156d4
|
@ -11,6 +11,7 @@
|
|||
#import <React/RCTEventEmitter.h>
|
||||
|
||||
RCT_EXTERN void RCTEnableAppearancePreference(BOOL enabled);
|
||||
RCT_EXTERN void RCTOverrideAppearancePreference(NSString *const);
|
||||
|
||||
@interface RCTAppearance : RCTEventEmitter <RCTBridgeModule>
|
||||
@end
|
||||
|
|
|
@ -23,6 +23,11 @@ void RCTEnableAppearancePreference(BOOL enabled) {
|
|||
sAppearancePreferenceEnabled = enabled;
|
||||
}
|
||||
|
||||
static NSString *sColorSchemeOverride = nil;
|
||||
void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride) {
|
||||
sColorSchemeOverride = colorSchemeOverride;
|
||||
}
|
||||
|
||||
static NSString *RCTColorSchemePreference(UITraitCollection *traitCollection)
|
||||
{
|
||||
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
|
||||
|
@ -30,6 +35,10 @@ static NSString *RCTColorSchemePreference(UITraitCollection *traitCollection)
|
|||
static NSDictionary *appearances;
|
||||
static dispatch_once_t onceToken;
|
||||
|
||||
if (sColorSchemeOverride) {
|
||||
return sColorSchemeOverride;
|
||||
}
|
||||
|
||||
dispatch_once(&onceToken, ^{
|
||||
appearances = @{
|
||||
@(UIUserInterfaceStyleLight): RCTAppearanceColorSchemeLight,
|
||||
|
|
Загрузка…
Ссылка в новой задаче