Skip to content
Permalink
Browse files
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
  • Loading branch information
Zack Argyle authored and facebook-github-bot committed Dec 20, 2019
1 parent d43059d commit fa65b156d4109e6a3121484b601358b11cf0d541
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
@@ -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,13 +23,22 @@ 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
if (@available(iOS 13.0, *)) {
static NSDictionary *appearances;
static dispatch_once_t onceToken;

if (sColorSchemeOverride) {
return sColorSchemeOverride;
}

dispatch_once(&onceToken, ^{
appearances = @{
@(UIUserInterfaceStyleLight): RCTAppearanceColorSchemeLight,

0 comments on commit fa65b15

Please sign in to comment.