Skip to content

Commit e14757f

Browse files
committed
[PlatformColor] Properly add macOS version
1 parent 2409ea7 commit e14757f

File tree

6 files changed

+99
-16
lines changed

6 files changed

+99
-16
lines changed

Libraries/StyleSheet/PlatformColorValueTypes.macos.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ export const PlatformColor = (...names: Array<string>): ColorValue => {
2525
return {semantic: names};
2626
};
2727

28-
export type DynamicColorIOSTuplePrivate = {
28+
export type DynamicColorMacOSTuplePrivate = {
2929
light: ColorValue,
3030
dark: ColorValue,
3131
};
3232

33-
export const DynamicColorIOSPrivate = (
34-
tuple: DynamicColorIOSTuplePrivate,
33+
export const DynamicColorMacOSPrivate = (
34+
tuple: DynamicColorMacOSTuplePrivate,
3535
): ColorValue => {
3636
return {dynamic: {light: tuple.light, dark: tuple.dark}};
3737
};
@@ -40,7 +40,7 @@ export const normalizeColorObject = (
4040
color: NativeColorValue,
4141
): ?ProcessedColorValue => {
4242
if ('semantic' in color) {
43-
// an ios semantic color
43+
// a macOS semantic color
4444
return color;
4545
} else if ('dynamic' in color && color.dynamic !== undefined) {
4646
const normalizeColor = require('./normalizeColor');

Libraries/StyleSheet/PlatformColorValueTypesIOS.macos.js renamed to Libraries/StyleSheet/PlatformColorValueTypesMacOS.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
'use strict';
1212

1313
import type {ColorValue} from './StyleSheetTypes';
14-
import {DynamicColorIOSPrivate} from './PlatformColorValueTypes';
1514

16-
export type DynamicColorIOSTuple = {
15+
export type DynamicColorMacOSTuple = {
1716
light: ColorValue,
1817
dark: ColorValue,
1918
};
2019

21-
export const DynamicColorIOS = (tuple: DynamicColorIOSTuple): ColorValue => {
22-
return DynamicColorIOSPrivate({light: tuple.light, dark: tuple.dark});
20+
export const DynamicColorMacOS = (
21+
tuple: DynamicColorMacOSTuple,
22+
): ColorValue => {
23+
throw new Error('DynamicColorMacOS is not available on this platform.');
2324
};
2425
// ]TODO(macOS ISS#2323203)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow strict-local
9+
*/
10+
// [TODO(macOS ISS#2323203)
11+
'use strict';
12+
13+
import type {ColorValue} from './StyleSheetTypes';
14+
import {DynamicColorMacOSPrivate} from './PlatformColorValueTypes';
15+
16+
export type DynamicColorMacOSTuple = {
17+
light: ColorValue,
18+
dark: ColorValue,
19+
};
20+
21+
export const DynamicColorMacOS = (
22+
tuple: DynamicColorMacOSTuple,
23+
): ColorValue => {
24+
return DynamicColorMacOSPrivate({light: tuple.light, dark: tuple.dark});
25+
};
26+
// ]TODO(macOS ISS#2323203)

RNTester/js/RNTesterApp.ios.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
Platform, // TODO(OSS Candidate ISS#2710739)
3030
PlatformColor, // TODO(OSS Candidate ISS#2710739)
3131
DynamicColorIOS, // TODO(OSS Candidate ISS#2710739)
32+
DynamicColorMacOS, // TODO(macOS ISS#2323203)
3233
SafeAreaView,
3334
StyleSheet,
3435
Text,
@@ -249,7 +250,12 @@ const styles = StyleSheet.create({
249250
fontSize: 19,
250251
fontWeight: '600',
251252
textAlign: 'center',
252-
color: DynamicColorIOS({light: 'black', dark: 'white'}), // TODO(OSS Candidate ISS#2710739)
253+
color:
254+
// [TODO(macOS ISS#2323203)
255+
Platform.OS === 'macos'
256+
? DynamicColorMacOS({light: 'black', dark: 'white'})
257+
: DynamicColorIOS({light: 'black', dark: 'white'}), // TODO(OSS Candidate ISS#2710739)
258+
// ]TODO(macOS ISS#2323203)
253259
},
254260
exampleContainer: {
255261
flex: 1,

RNTester/js/examples/PlatformColor/PlatformColorExample.js

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Platform from '../../../../Libraries/Utilities/Platform';
1616
const {
1717
ColorAndroid,
1818
DynamicColorIOS,
19+
DynamicColorMacOS,
1920
PlatformColor,
2021
StyleSheet,
2122
Text,
@@ -228,7 +229,42 @@ function FallbackColorsExample() {
228229
}
229230

230231
function DynamicColorsExample() {
231-
return Platform.OS === 'ios' ? (
232+
// [TODO(macOS ISS#2323203)
233+
return Platform.OS === 'macos' ? (
234+
<View style={styles.column}>
235+
<View style={styles.row}>
236+
<Text style={styles.labelCell}>
237+
DynamicColorMacOS({'{\n'}
238+
{' '}light: 'red', dark: 'blue'{'\n'}
239+
{'}'})
240+
</Text>
241+
<View
242+
style={{
243+
...styles.colorCell,
244+
backgroundColor: DynamicColorMacOS({light: 'red', dark: 'blue'}),
245+
}}
246+
/>
247+
</View>
248+
<View style={styles.row}>
249+
<Text style={styles.labelCell}>
250+
DynamicColorMacOS({'{\n'}
251+
{' '}light: PlatformColor('systemBlueColor'),{'\n'}
252+
{' '}dark: PlatformColor('systemRedColor'),{'\n'}
253+
{'}'})
254+
</Text>
255+
<View
256+
style={{
257+
...styles.colorCell,
258+
backgroundColor: DynamicColorMacOS({
259+
light: PlatformColor('systemBlueColor'),
260+
dark: PlatformColor('systemRedColor'),
261+
}),
262+
}}
263+
/>
264+
</View>
265+
</View>
266+
) : // ]TODO(macOS ISS#2323203)
267+
Platform.OS === 'ios' ? (
232268
<View style={styles.column}>
233269
<View style={styles.row}>
234270
<Text style={styles.labelCell}>
@@ -289,17 +325,26 @@ function VariantColorsExample() {
289325
<View style={styles.column}>
290326
<View style={styles.row}>
291327
<Text style={styles.labelCell}>
292-
{Platform.OS === 'ios' || Platform.OS === 'macos' // TODO(macOS ISS#2323203)
293-
? "DynamicColorIOS({light: 'red', dark: 'blue'})"
294-
: "ColorAndroid('?attr/colorAccent')"}
328+
{// [TODO(OSS Candidate ISS#2710739)
329+
Platform.select({
330+
ios: "DynamicColorIOS({light: 'red', dark: 'blue'})",
331+
android: "ColorAndroid('?attr/colorAccent')",
332+
macos: "DynamicColorMacOS({light: 'red', dark: 'blue'})",
333+
})
334+
// ]TODO(OSS Candidate ISS#2710739)
335+
}
295336
</Text>
296337
<View
297338
style={{
298339
...styles.colorCell,
299340
backgroundColor:
300-
Platform.OS === 'ios' || Platform.OS === 'macos' // TODO(macOS ISS#2323203)
341+
Platform.OS === 'ios'
301342
? DynamicColorIOS({light: 'red', dark: 'blue'})
302-
: ColorAndroid('?attr/colorAccent'),
343+
: // [TODO(macOS ISS#2323203)
344+
Platform.OS === 'macos'
345+
? DynamicColorMacOS({light: 'red', dark: 'blue'})
346+
: // ]TODO(macOS ISS#2323203)
347+
ColorAndroid('?attr/colorAccent'),
303348
}}
304349
/>
305350
</View>
@@ -336,7 +381,7 @@ exports.examples = [
336381
},
337382
},
338383
{
339-
title: 'iOS Dynamic Colors',
384+
title: 'Dynamic Colors', // TODO(OSS Candidate ISS#2710739)
340385
render(): React.Element<any> {
341386
return <DynamicColorsExample />;
342387
},

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import typeof Platform from './Libraries/Utilities/Platform';
9898
import typeof processColor from './Libraries/StyleSheet/processColor';
9999
import typeof {PlatformColor} from './Libraries/StyleSheet/PlatformColorValueTypes';
100100
import typeof {DynamicColorIOS} from './Libraries/StyleSheet/PlatformColorValueTypesIOS';
101+
import typeof {DynamicColorMacOS} from './Libraries/StyleSheet/PlatformColorValueTypesMacOS'; // TODO(macOS ISS#2323203)
101102
import typeof {ColorAndroid} from './Libraries/StyleSheet/PlatformColorValueTypesAndroid';
102103
import typeof RootTagContext from './Libraries/ReactNative/RootTagContext';
103104
import typeof DeprecatedColorPropType from './Libraries/DeprecatedPropTypes/DeprecatedColorPropType';
@@ -495,6 +496,10 @@ module.exports = {
495496
return require('./Libraries/StyleSheet/PlatformColorValueTypesIOS')
496497
.DynamicColorIOS;
497498
},
499+
get DynamicColorMacOS(): DynamicColorMacOS {
500+
return require('./Libraries/StyleSheet/PlatformColorValueTypesMacOS')
501+
.DynamicColorMacOS;
502+
},
498503
get ColorAndroid(): ColorAndroid {
499504
return require('./Libraries/StyleSheet/PlatformColorValueTypesAndroid')
500505
.ColorAndroid;

0 commit comments

Comments
 (0)