Skip to content

Commit 411c344

Browse files
tom-unfacebook-github-bot
authored andcommitted
Remove ColorAndroid function as it adds no value over PlatfromColor (#28577)
Summary: This change removes the `ColorAndroid` API. It was added more as a validation tool than as something useful to a developer. When making the original [PlatformColor PR](#27908) we felt it was valuable and useful to have working platform specific methods for the two platforms in core to test that the pattern worked in app code (PlatformColorExample.js in RNTester) and that the Flow validation worked, etc. Practically `PlatformColor()` is more useful to a developer on Android than `ColorAndroid()`. Now that the construct has served its purpose, this PR removes the `ColorAndroid` function and its related tests and other collateral. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Removed] - Remove ColorAndroid function as it adds no value over PlatfromColor Pull Request resolved: #28577 Test Plan: RNTester in both iOS and Android was tested. Jest tests, Flow checks, Lint checks all pass. Reviewed By: cpojer Differential Revision: D20952613 Pulled By: TheSavior fbshipit-source-id: 7d2cbaa2a347fffe59a1f3a26a210676008fdac0
1 parent 44ec762 commit 411c344

File tree

7 files changed

+4
-100
lines changed

7 files changed

+4
-100
lines changed

Libraries/StyleSheet/PlatformColorValueTypes.android.js

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ export const PlatformColor = (...names: Array<string>): ColorValue => {
2121
return {resource_paths: names};
2222
};
2323

24-
export const ColorAndroidPrivate = (color: string): ColorValue => {
25-
return {resource_paths: [color]};
26-
};
27-
2824
export const normalizeColorObject = (
2925
color: NativeColorValue,
3026
): ?ProcessedColorValue => {

Libraries/StyleSheet/PlatformColorValueTypesAndroid.android.js

-18
This file was deleted.

Libraries/StyleSheet/PlatformColorValueTypesAndroid.js

-17
This file was deleted.

RNTester/js/examples/PlatformColor/PlatformColorExample.js

+3-34
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@
1313
const React = require('react');
1414
const ReactNative = require('react-native');
1515
import Platform from '../../../../Libraries/Utilities/Platform';
16-
const {
17-
ColorAndroid,
18-
DynamicColorIOS,
19-
PlatformColor,
20-
StyleSheet,
21-
Text,
22-
View,
23-
} = ReactNative;
16+
const {DynamicColorIOS, PlatformColor, StyleSheet, Text, View} = ReactNative;
2417

2518
function PlatformColorsExample() {
2619
function createTable() {
@@ -263,40 +256,22 @@ function DynamicColorsExample() {
263256
);
264257
}
265258

266-
function AndroidColorsExample() {
267-
return Platform.OS === 'android' ? (
268-
<View style={styles.column}>
269-
<View style={styles.row}>
270-
<Text style={styles.labelCell}>ColorAndroid('?attr/colorAccent')</Text>
271-
<View
272-
style={{
273-
...styles.colorCell,
274-
backgroundColor: ColorAndroid('?attr/colorAccent'),
275-
}}
276-
/>
277-
</View>
278-
</View>
279-
) : (
280-
<Text style={styles.labelCell}>Not applicable on this platform</Text>
281-
);
282-
}
283-
284259
function VariantColorsExample() {
285260
return (
286261
<View style={styles.column}>
287262
<View style={styles.row}>
288263
<Text style={styles.labelCell}>
289264
{Platform.OS === 'ios'
290265
? "DynamicColorIOS({light: 'red', dark: 'blue'})"
291-
: "ColorAndroid('?attr/colorAccent')"}
266+
: "PlatformColor('?attr/colorAccent')"}
292267
</Text>
293268
<View
294269
style={{
295270
...styles.colorCell,
296271
backgroundColor:
297272
Platform.OS === 'ios'
298273
? DynamicColorIOS({light: 'red', dark: 'blue'})
299-
: ColorAndroid('?attr/colorAccent'),
274+
: PlatformColor('?attr/colorAccent'),
300275
}}
301276
/>
302277
</View>
@@ -340,12 +315,6 @@ exports.examples = [
340315
return <DynamicColorsExample />;
341316
},
342317
},
343-
{
344-
title: 'Android Colors',
345-
render(): React.Element<any> {
346-
return <AndroidColorsExample />;
347-
},
348-
},
349318
{
350319
title: 'Variant Colors',
351320
render(): React.Element<any> {

index.js

-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ import typeof Platform from './Libraries/Utilities/Platform';
9595
import typeof processColor from './Libraries/StyleSheet/processColor';
9696
import typeof {PlatformColor} from './Libraries/StyleSheet/PlatformColorValueTypes';
9797
import typeof {DynamicColorIOS} from './Libraries/StyleSheet/PlatformColorValueTypesIOS';
98-
import typeof {ColorAndroid} from './Libraries/StyleSheet/PlatformColorValueTypesAndroid';
9998
import typeof RootTagContext from './Libraries/ReactNative/RootTagContext';
10099
import typeof DeprecatedColorPropType from './Libraries/DeprecatedPropTypes/DeprecatedColorPropType';
101100
import typeof DeprecatedEdgeInsetsPropType from './Libraries/DeprecatedPropTypes/DeprecatedEdgeInsetsPropType';
@@ -463,10 +462,6 @@ module.exports = {
463462
return require('./Libraries/StyleSheet/PlatformColorValueTypesIOS')
464463
.DynamicColorIOS;
465464
},
466-
get ColorAndroid(): ColorAndroid {
467-
return require('./Libraries/StyleSheet/PlatformColorValueTypesAndroid')
468-
.ColorAndroid;
469-
},
470465
get requireNativeComponent(): <T>(
471466
uiViewClassName: string,
472467
) => HostComponent<T> {

packages/eslint-plugin-react-native-community/__tests__/platform-colors-test.js

-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ eslintTester.run('../platform-colors', rule, {
2222
"const color = PlatformColor('controlAccentColor', 'controlColor');",
2323
"const color = DynamicColorIOS({light: 'black', dark: 'white'});",
2424
"const color = DynamicColorIOS({light: PlatformColor('black'), dark: PlatformColor('white')});",
25-
"const color = ColorAndroid('?attr/colorAccent')",
2625
],
2726
invalid: [
2827
{
@@ -49,14 +48,5 @@ eslintTester.run('../platform-colors', rule, {
4948
"const white = 'white'; const color = DynamicColorIOS({light: 'black', dark: white});",
5049
errors: [{message: rule.meta.messages.dynamicColorIOSDark}],
5150
},
52-
{
53-
code: 'const color = ColorAndroid();',
54-
errors: [{message: rule.meta.messages.colorAndroidArg}],
55-
},
56-
{
57-
code:
58-
"const colorAccent = '?attr/colorAccent'; const color = ColorAndroid(colorAccent);",
59-
errors: [{message: rule.meta.messages.colorAndroidArg}],
60-
},
6151
],
6252
});

packages/eslint-plugin-react-native-community/platform-colors.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
type: 'problem',
1313
docs: {
1414
description:
15-
'Ensure that PlatformColor(), DynamicColorIOS(), and ColorAndroid() are passed literals of the expected shape.',
15+
'Ensure that PlatformColor() and DynamicColorIOS() are passed literals of the expected shape.',
1616
},
1717
messages: {
1818
platformColorArgsLength:
@@ -25,8 +25,6 @@ module.exports = {
2525
'DynamicColorIOS() light value must be either a literal or a PlatformColor() call.',
2626
dynamicColorIOSDark:
2727
'DynamicColorIOS() dark value must be either a literal or a PlatformColor() call.',
28-
colorAndroidArg:
29-
'ColorAndroid() must take a single argument that is a literal.',
3028
},
3129
schema: [],
3230
},
@@ -103,15 +101,6 @@ module.exports = {
103101
});
104102
return;
105103
}
106-
} else if (node.callee.name === 'ColorAndroid') {
107-
const args = node.arguments;
108-
if (!(args.length === 1 && args[0].type === 'Literal')) {
109-
context.report({
110-
node,
111-
messageId: 'colorAndroidArg',
112-
});
113-
return;
114-
}
115104
}
116105
},
117106
};

0 commit comments

Comments
 (0)