@@ -36,28 +36,6 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
36
36
return sColorSchemeOverride ;
37
37
}
38
38
39
- <<<<<<< HEAD
40
- ||||||| parent of 5715b1498ee (Make requesting the trait collection synchronous)
41
- static UITraitCollection *getKeyWindowTraitCollection ()
42
- {
43
- __block UITraitCollection *traitCollection = nil ;
44
- RCTExecuteOnMainQueue (^{
45
- traitCollection = RCTSharedApplication ().delegate .window .traitCollection ;
46
- });
47
- return traitCollection;
48
- }
49
-
50
- =======
51
- static UITraitCollection *getKeyWindowTraitCollection ()
52
- {
53
- __block UITraitCollection *traitCollection = nil ;
54
- RCTUnsafeExecuteOnMainQueueSync (^{
55
- traitCollection = RCTSharedApplication ().delegate .window .traitCollection ;
56
- });
57
- return traitCollection;
58
- }
59
-
60
- >>>>>>> 5715b1498ee (Make requesting the trait collection synchronous)
61
39
NSString *RCTColorSchemePreference (UITraitCollection *traitCollection)
62
40
{
63
41
static NSDictionary *appearances;
@@ -79,7 +57,6 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
79
57
return RCTAppearanceColorSchemeLight;
80
58
}
81
59
82
- traitCollection = traitCollection ?: [UITraitCollection currentTraitCollection ];
83
60
return appearances[@(traitCollection.userInterfaceStyle)] ?: RCTAppearanceColorSchemeLight;
84
61
}
85
62
@@ -90,6 +67,19 @@ @implementation RCTAppearance {
90
67
NSString *_currentColorScheme;
91
68
}
92
69
70
+ - (instancetype )init
71
+ {
72
+ if ((self = [super init ])) {
73
+ UITraitCollection *traitCollection = RCTSharedApplication ().delegate .window .traitCollection ;
74
+ _currentColorScheme = RCTColorSchemePreference (traitCollection);
75
+ [[NSNotificationCenter defaultCenter ] addObserver: self
76
+ selector: @selector (appearanceChanged: )
77
+ name: RCTUserInterfaceStyleDidChangeNotification
78
+ object: nil ];
79
+ }
80
+ return self;
81
+ }
82
+
93
83
RCT_EXPORT_MODULE (Appearance)
94
84
95
85
+ (BOOL )requiresMainQueueSetup
@@ -119,9 +109,6 @@ - (dispatch_queue_t)methodQueue
119
109
120
110
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD (NSString *, getColorScheme)
121
111
{
122
- if (_currentColorScheme == nil ) {
123
- _currentColorScheme = RCTColorSchemePreference (nil );
124
- }
125
112
return _currentColorScheme;
126
113
}
127
114
@@ -148,10 +135,7 @@ - (void)appearanceChanged:(NSNotification *)notification
148
135
149
136
- (void )startObserving
150
137
{
151
- [[NSNotificationCenter defaultCenter ] addObserver: self
152
- selector: @selector (appearanceChanged: )
153
- name: RCTUserInterfaceStyleDidChangeNotification
154
- object: nil ];
138
+
155
139
}
156
140
157
141
- (void )stopObserving
0 commit comments