Skip to content
Open
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
20 changes: 15 additions & 5 deletions packages/react-native/React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ void RCTUseKeyWindowForSystemStyle(BOOL useMainScreen)
return RCTAppearanceColorSchemeLight;
}

appearance = appearance ?: [NSApp effectiveAppearance];
__block NSAppearance *resolvedAppearance = appearance;
RCTUnsafeExecuteOnMainQueueSync(^{
resolvedAppearance = resolvedAppearance ?: [NSApp effectiveAppearance];
});

NSAppearanceName appearanceName = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
NSAppearanceName appearanceName = [resolvedAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
return appearances[appearanceName] ?: RCTAppearanceColorSchemeLight;
}
#endif // macOS]
Expand All @@ -119,7 +122,14 @@ - (instancetype)init
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
_currentColorScheme = RCTColorSchemePreference(traitCollection);
#else // [macOS
NSAppearance *appearance = RCTSharedApplication().appearance;
// Initialize with a concrete NSAppearance, fetched safely on the main thread.
__block NSAppearance *appearance = nil;
RCTUnsafeExecuteOnMainQueueSync(^{
appearance = RCTSharedApplication().appearance ?: [NSApp effectiveAppearance];
if (!appearance) {
appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
}
});
_currentColorScheme = RCTColorSchemePreference(appearance);
#endif // macOS]
[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down Expand Up @@ -173,7 +183,7 @@ - (dispatch_queue_t)methodQueue
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getColorScheme)
{
if (!sIsAppearancePreferenceSet) {
#if !TARGET_OS_OSX // [macOS
#if !TARGET_OS_OSX // [macOS]
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
_currentColorScheme = RCTColorSchemePreference(traitCollection);
#else // [macOS
Expand Down Expand Up @@ -228,4 +238,4 @@ - (void)invalidate
Class RCTAppearanceCls(void)
{
return RCTAppearance.class;
}
}
Loading