Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/react-native/React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
NSString *const RCTAppearanceColorSchemeLight = @"light";
NSString *const RCTAppearanceColorSchemeDark = @"dark";

static BOOL sIsAppearancePreferenceSet = NO;

static BOOL sAppearancePreferenceEnabled = YES;
void RCTEnableAppearancePreference(BOOL enabled)
{
Expand Down Expand Up @@ -62,6 +64,12 @@ void RCTUseKeyWindowForSystemStyle(BOOL useMainScreen)
// Return the default if the app doesn't allow different color schemes.
return RCTAppearanceColorSchemeLight;
}

if (appearances[@(traitCollection.userInterfaceStyle)]){
sIsAppearancePreferenceSet = YES;
return appearances[@(traitCollection.userInterfaceStyle)];
}

UIUserInterfaceStyle systemStyle = sUseKeyWindowForSystemStyle ? RCTKeyWindow().traitCollection.userInterfaceStyle
: traitCollection.userInterfaceStyle;
return appearances[@(systemStyle)] ?: RCTAppearanceColorSchemeLight;
Expand Down Expand Up @@ -116,6 +124,10 @@ - (dispatch_queue_t)methodQueue

RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getColorScheme)
{
if (!sIsAppearancePreferenceSet) {
UITraitCollection *traitCollection = RCTKeyWindow().traitCollection;
_currentColorScheme = RCTColorSchemePreference(traitCollection);
}
return _currentColorScheme;
}

Expand Down