@@ -36,15 +36,6 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
36
36
return sColorSchemeOverride ;
37
37
}
38
38
39
- static UITraitCollection *getKeyWindowTraitCollection ()
40
- {
41
- __block UITraitCollection *traitCollection = nil ;
42
- RCTUnsafeExecuteOnMainQueueSync (^{
43
- traitCollection = RCTSharedApplication ().delegate .window .traitCollection ;
44
- });
45
- return traitCollection;
46
- }
47
-
48
39
NSString *RCTColorSchemePreference (UITraitCollection *traitCollection)
49
40
{
50
41
static NSDictionary *appearances;
@@ -66,7 +57,6 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
66
57
return RCTAppearanceColorSchemeLight;
67
58
}
68
59
69
- traitCollection = traitCollection ?: getKeyWindowTraitCollection ();
70
60
return appearances[@(traitCollection.userInterfaceStyle)] ?: RCTAppearanceColorSchemeLight;
71
61
}
72
62
@@ -77,6 +67,15 @@ @implementation RCTAppearance {
77
67
NSString *_currentColorScheme;
78
68
}
79
69
70
+ - (instancetype )init
71
+ {
72
+ if ((self = [super init ])) {
73
+ UITraitCollection *traitCollection = RCTSharedApplication ().delegate .window .traitCollection ;
74
+ _currentColorScheme = RCTColorSchemePreference (traitCollection);
75
+ }
76
+ return self;
77
+ }
78
+
80
79
RCT_EXPORT_MODULE (Appearance)
81
80
82
81
+ (BOOL )requiresMainQueueSetup
@@ -106,9 +105,6 @@ - (dispatch_queue_t)methodQueue
106
105
107
106
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD (NSString *, getColorScheme)
108
107
{
109
- if (_currentColorScheme == nil ) {
110
- _currentColorScheme = RCTColorSchemePreference (nil );
111
- }
112
108
return _currentColorScheme;
113
109
}
114
110
0 commit comments