Skip to content

Commit

Permalink
fix: return the correct default trait collection
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjhughes committed Sep 10, 2023
1 parent 17ecae9 commit 3d194cc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/react-native/React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
return sColorSchemeOverride;
}

UITraitCollection* getKeyWindowTraitCollection() {
if ([NSThread isMainThread]) {
return [UIApplication sharedApplication].delegate.window.traitCollection;
} else {
__block UITraitCollection* traitCollection = nil;
dispatch_sync(dispatch_get_main_queue(), ^{
traitCollection = [UIApplication sharedApplication].delegate.window.traitCollection;
});
return traitCollection;
}
}

NSString *RCTColorSchemePreference(UITraitCollection *traitCollection)
{
static NSDictionary *appearances;
Expand All @@ -57,7 +69,7 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
return RCTAppearanceColorSchemeLight;
}

traitCollection = traitCollection ?: [UITraitCollection currentTraitCollection];
traitCollection = traitCollection ?: getKeyWindowTraitCollection();
return appearances[@(traitCollection.userInterfaceStyle)] ?: RCTAppearanceColorSchemeLight;

// Default to light on older OS version - same behavior as Android.
Expand Down

0 comments on commit 3d194cc

Please sign in to comment.