Skip to content

Commit 5715b14

Browse files
committed
Make requesting the trait collection synchronous
1 parent 855f227 commit 5715b14

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/react-native/React/CoreModules/RCTAppearance.mm

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
3939
static UITraitCollection *getKeyWindowTraitCollection()
4040
{
4141
__block UITraitCollection *traitCollection = nil;
42-
RCTExecuteOnMainQueue(^{
43-
traitCollection = RCTSharedApplication().delegate.window.traitCollection;
44-
});
45-
return traitCollection;
42+
if (RCTIsMainQueue()) {
43+
return RCTSharedApplication().delegate.window.traitCollection;
44+
} else {
45+
__block UITraitCollection* traitCollection = nil;
46+
dispatch_sync(dispatch_get_main_queue(), ^{
47+
traitCollection = RCTSharedApplication().delegate.window.traitCollection;
48+
});
49+
return traitCollection;
50+
}
4651
}
4752

4853
NSString *RCTColorSchemePreference(UITraitCollection *traitCollection)
@@ -68,9 +73,6 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
6873

6974
traitCollection = traitCollection ?: getKeyWindowTraitCollection();
7075
return appearances[@(traitCollection.userInterfaceStyle)] ?: RCTAppearanceColorSchemeLight;
71-
72-
// Default to light on older OS version - same behavior as Android.
73-
return RCTAppearanceColorSchemeLight;
7476
}
7577

7678
@interface RCTAppearance () <NativeAppearanceSpec>

0 commit comments

Comments
 (0)