@@ -152,15 +152,14 @@ int32_t ColorFromUIColor(RCTPlatformColor *color) // [macOS]
152152#else // [macOS
153153 // Resolve dynamic/semantic colors against the current effective appearance
154154 // so that dark mode colors are correctly extracted.
155- NSAppearance *previousAppearance = NSAppearance .currentAppearance ;
156- NSAppearance .currentAppearance = [NSApp effectiveAppearance ];
157- NSColor *resolvedColor = [color colorUsingColorSpace: [NSColorSpace sRGBColorSpace ]];
158- if (resolvedColor) {
159- [resolvedColor getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
160- } else {
161- [color getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
162- }
163- NSAppearance .currentAppearance = previousAppearance;
155+ [[NSApp effectiveAppearance ] performAsCurrentDrawingAppearance: ^{
156+ NSColor *resolvedColor = [color colorUsingColorSpace: [NSColorSpace sRGBColorSpace ]];
157+ if (resolvedColor) {
158+ [resolvedColor getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
159+ } else {
160+ [color getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
161+ }
162+ }];
164163#endif // macOS]
165164 return ColorFromColorComponents ({(float )rgba[0 ], (float )rgba[1 ], (float )rgba[2 ], (float )rgba[3 ]});
166165}
@@ -245,27 +244,27 @@ int32_t ColorFromUIColor(const std::shared_ptr<void> &uiColor)
245244 // Hash both light and dark appearance colors to properly distinguish
246245 // dynamic colors that change with appearance.
247246 RCTPlatformColor *color = (RCTPlatformColor *)unwrapManagedObject (uiColor);
248- int32_t darkColor = 0 ;
249- int32_t lightColor = 0 ;
250- NSAppearance *previousAppearance = NSAppearance .currentAppearance ;
251-
252- NSAppearance .currentAppearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua ];
253- NSColor *darkResolved = [color colorUsingColorSpace: [NSColorSpace sRGBColorSpace ]];
254- if (darkResolved) {
255- CGFloat rgba[4 ];
256- [darkResolved getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
257- darkColor = ColorFromColorComponents ({(float )rgba[0 ], (float )rgba[1 ], (float )rgba[2 ], (float )rgba[3 ]});
258- }
259-
260- NSAppearance .currentAppearance = [NSAppearance appearanceNamed: NSAppearanceNameAqua ];
261- NSColor *lightResolved = [color colorUsingColorSpace: [NSColorSpace sRGBColorSpace ]];
262- if (lightResolved) {
263- CGFloat rgba[4 ];
264- [lightResolved getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
265- lightColor = ColorFromColorComponents ({(float )rgba[0 ], (float )rgba[1 ], (float )rgba[2 ], (float )rgba[3 ]});
266- }
247+ __block int32_t darkColor = 0 ;
248+ __block int32_t lightColor = 0 ;
249+
250+ [[NSAppearance appearanceNamed: NSAppearanceNameDarkAqua ] performAsCurrentDrawingAppearance: ^{
251+ NSColor *resolved = [color colorUsingColorSpace: [NSColorSpace sRGBColorSpace ]];
252+ if (resolved) {
253+ CGFloat rgba[4 ];
254+ [resolved getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
255+ darkColor = ColorFromColorComponents ({(float )rgba[0 ], (float )rgba[1 ], (float )rgba[2 ], (float )rgba[3 ]});
256+ }
257+ }];
258+
259+ [[NSAppearance appearanceNamed: NSAppearanceNameAqua ] performAsCurrentDrawingAppearance: ^{
260+ NSColor *resolved = [color colorUsingColorSpace: [NSColorSpace sRGBColorSpace ]];
261+ if (resolved) {
262+ CGFloat rgba[4 ];
263+ [resolved getRed: &rgba[0 ] green: &rgba[1 ] blue: &rgba[2 ] alpha: &rgba[3 ]];
264+ lightColor = ColorFromColorComponents ({(float )rgba[0 ], (float )rgba[1 ], (float )rgba[2 ], (float )rgba[3 ]});
265+ }
266+ }];
267267
268- NSAppearance .currentAppearance = previousAppearance;
269268 return facebook::react::hash_combine (darkColor, lightColor);
270269#endif // macOS]
271270}
0 commit comments