Skip to content

Commit

Permalink
Add RCTOverrideAppearancePreference to iOS Appearance module
Browse files Browse the repository at this point in the history
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 fa65b15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions React/CoreModules/RCTAppearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fa65b15

Please sign in to comment.