Skip to content

Commit d19667f

Browse files
Saadnajmiclaude
andcommitted
Clean up: fix macOS diff tags and remove test-only changes
- Fix bare #endif to use proper #endif // macOS] tags per conventions - Revert Playground and testerStateUtils to upstream defaults (test-only) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0be4f94 commit d19667f

4 files changed

Lines changed: 51 additions & 153 deletions

File tree

packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@
2020

2121
namespace facebook::react {
2222

23+
#if TARGET_OS_OSX // [macOS
24+
RCTUIColor *_Nullable UIColorFromColorWithSystemEffect(
25+
RCTUIColor *baseColor,
26+
const std::string &systemEffectString)
27+
{
28+
if (baseColor == nil) {
29+
return nil;
30+
}
31+
32+
NSColor *colorWithEffect = baseColor;
33+
if (!systemEffectString.empty()) {
34+
if (systemEffectString == "none") {
35+
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectNone];
36+
} else if (systemEffectString == "pressed") {
37+
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectPressed];
38+
} else if (systemEffectString == "deepPressed") {
39+
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectDeepPressed];
40+
} else if (systemEffectString == "disabled") {
41+
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectDisabled];
42+
} else if (systemEffectString == "rollover") {
43+
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectRollover];
44+
}
45+
}
46+
return colorWithEffect;
47+
}
48+
#endif // macOS]
49+
2350
namespace {
2451

2552
bool UIColorIsP3ColorSpace(const std::shared_ptr<void> &uiColor)
@@ -134,7 +161,7 @@ int32_t ColorFromUIColor(RCTPlatformColor *color) // [macOS]
134161
NSAppearance.currentAppearance = previousAppearance;
135162
#else // macOS]
136163
[color getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]];
137-
#endif
164+
#endif // macOS]
138165
return ColorFromColorComponents({(float)rgba[0], (float)rgba[1], (float)rgba[2], (float)rgba[3]});
139166
}
140167

@@ -262,6 +289,21 @@ int32_t ColorFromUIColor(const std::shared_ptr<void> &uiColor)
262289
0);
263290
}
264291

292+
#if TARGET_OS_OSX // [macOS
293+
Color::Color(const ColorWithSystemEffect &colorWithSystemEffect)
294+
{
295+
RCTUIColor *baseColor = UIColorFromInt32(colorWithSystemEffect.color);
296+
RCTUIColor *colorWithEffect =
297+
UIColorFromColorWithSystemEffect(baseColor, colorWithSystemEffect.effect);
298+
if (colorWithEffect != nil) {
299+
uiColor_ = wrapManagedObject(colorWithEffect);
300+
}
301+
uiColorHashValue_ = facebook::react::hash_combine(
302+
colorWithSystemEffect.color,
303+
std::hash<std::string>{}(colorWithSystemEffect.effect));
304+
}
305+
#endif // macOS
306+
265307
Color::Color(const ColorComponents &components)
266308
{
267309
uiColor_ = wrapManagedObject(UIColorFromComponentsColor(components));

packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
return colorObject;
317317
}
318318
}
319-
#endif
319+
#endif // macOS]
320320
}
321321
return nil;
322322
}
@@ -342,7 +342,7 @@
342342
[finalColor getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]];
343343
#else // macOS]
344344
[color getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]];
345-
#endif
345+
#endif // macOS]
346346
return {(float)rgba[0], (float)rgba[1], (float)rgba[2], (float)rgba[3]};
347347
}
348348

packages/rn-tester/js/examples/Playground/RNTesterPlayground.js

Lines changed: 3 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -12,121 +12,14 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
1212

1313
import RNTesterText from '../../components/RNTesterText';
1414
import * as React from 'react';
15-
import {Platform, PlatformColor, StyleSheet, View} from 'react-native';
16-
import {DynamicColorMacOS} from 'react-native'; // [macOS]
17-
18-
function ColorSwatch({
19-
color,
20-
label,
21-
}: {
22-
color: ReturnType<typeof PlatformColor>,
23-
label: string,
24-
}) {
25-
return (
26-
<View style={styles.row}>
27-
<View style={[styles.swatch, {backgroundColor: color}]} />
28-
<RNTesterText style={styles.label}>{label}</RNTesterText>
29-
</View>
30-
);
31-
}
15+
import {StyleSheet, View} from 'react-native';
3216

3317
function Playground() {
34-
if (Platform.OS !== 'macos') {
35-
return (
36-
<View style={styles.container}>
37-
<RNTesterText>This test is macOS-only.</RNTesterText>
38-
</View>
39-
);
40-
}
41-
4218
return (
4319
<View style={styles.container}>
44-
<RNTesterText style={styles.heading}>
45-
Fabric Dark Mode Color Test
46-
</RNTesterText>
47-
<RNTesterText style={styles.description}>
48-
These colors should change when you toggle between Light and Dark
49-
appearance in System Settings. If they all look the same in both modes,
50-
the bug is not fixed.
51-
</RNTesterText>
52-
53-
<RNTesterText style={styles.sectionTitle}>System Colors</RNTesterText>
54-
<ColorSwatch
55-
color={PlatformColor('systemBlueColor')}
56-
label="systemBlueColor"
57-
/>
58-
<ColorSwatch
59-
color={PlatformColor('systemRedColor')}
60-
label="systemRedColor"
61-
/>
62-
<ColorSwatch
63-
color={PlatformColor('systemGreenColor')}
64-
label="systemGreenColor"
65-
/>
66-
<ColorSwatch
67-
color={PlatformColor('systemOrangeColor')}
68-
label="systemOrangeColor"
69-
/>
70-
71-
<RNTesterText style={styles.sectionTitle}>Semantic Colors</RNTesterText>
72-
<ColorSwatch
73-
color={PlatformColor('labelColor')}
74-
label="labelColor"
75-
/>
76-
<ColorSwatch
77-
color={PlatformColor('secondaryLabelColor')}
78-
label="secondaryLabelColor"
79-
/>
80-
<ColorSwatch
81-
color={PlatformColor('windowBackgroundColor')}
82-
label="windowBackgroundColor"
83-
/>
84-
<ColorSwatch
85-
color={PlatformColor('controlBackgroundColor')}
86-
label="controlBackgroundColor"
87-
/>
88-
<ColorSwatch
89-
color={PlatformColor('textColor')}
90-
label="textColor"
91-
/>
92-
<ColorSwatch
93-
color={PlatformColor('separatorColor')}
94-
label="separatorColor"
95-
/>
96-
97-
<RNTesterText style={styles.sectionTitle}>
98-
DynamicColorMacOS
20+
<RNTesterText>
21+
Edit "RNTesterPlayground.js" to change this file
9922
</RNTesterText>
100-
<ColorSwatch
101-
color={DynamicColorMacOS({light: '#FF0000', dark: '#00FF00'})}
102-
label="light=red, dark=green"
103-
/>
104-
<ColorSwatch
105-
color={DynamicColorMacOS({light: '#0000FF', dark: '#FFFF00'})}
106-
label="light=blue, dark=yellow"
107-
/>
108-
109-
<RNTesterText style={styles.sectionTitle}>
110-
Background + Text Test
111-
</RNTesterText>
112-
<View
113-
style={[
114-
styles.textBox,
115-
{backgroundColor: PlatformColor('windowBackgroundColor')},
116-
]}>
117-
<RNTesterText style={{color: PlatformColor('labelColor')}}>
118-
This text should be readable in both light and dark mode
119-
</RNTesterText>
120-
</View>
121-
<View
122-
style={[
123-
styles.textBox,
124-
{backgroundColor: PlatformColor('controlBackgroundColor')},
125-
]}>
126-
<RNTesterText style={{color: PlatformColor('controlTextColor')}}>
127-
controlTextColor on controlBackgroundColor
128-
</RNTesterText>
129-
</View>
13023
</View>
13124
);
13225
}
@@ -135,43 +28,6 @@ const styles = StyleSheet.create({
13528
container: {
13629
padding: 10,
13730
},
138-
heading: {
139-
fontSize: 18,
140-
fontWeight: 'bold',
141-
marginBottom: 4,
142-
},
143-
description: {
144-
fontSize: 12,
145-
marginBottom: 12,
146-
color: 'gray',
147-
},
148-
sectionTitle: {
149-
fontSize: 14,
150-
fontWeight: '600',
151-
marginTop: 12,
152-
marginBottom: 6,
153-
},
154-
row: {
155-
flexDirection: 'row',
156-
alignItems: 'center',
157-
marginBottom: 4,
158-
},
159-
swatch: {
160-
width: 40,
161-
height: 24,
162-
borderRadius: 4,
163-
borderWidth: 1,
164-
borderColor: '#ccc',
165-
marginRight: 8,
166-
},
167-
label: {
168-
fontSize: 12,
169-
},
170-
textBox: {
171-
padding: 10,
172-
borderRadius: 6,
173-
marginBottom: 6,
174-
},
17531
});
17632

17733
export default ({

packages/rn-tester/js/utils/testerStateUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export const Screens = {
2525
} as const;
2626

2727
export const initialNavigationState: RNTesterNavigationState = {
28-
activeModuleKey: 'PlaygroundExample',
29-
activeModuleTitle: 'Playground',
28+
activeModuleKey: null,
29+
activeModuleTitle: null,
3030
activeModuleExampleKey: null,
31-
screen: Screens.PLAYGROUNDS,
31+
screen: Screens.COMPONENTS,
3232
recentlyUsed: {components: [], apis: []},
3333
hadDeepLink: false,
3434
};

0 commit comments

Comments
 (0)