Skip to content

Commit

Permalink
Remove ColorAndroid function as it adds no value over PlatfromColor (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
tom-un authored and facebook-github-bot committed Apr 10, 2020
1 parent 44ec762 commit 411c344
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 100 deletions.
4 changes: 0 additions & 4 deletions Libraries/StyleSheet/PlatformColorValueTypes.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export const PlatformColor = (...names: Array<string>): ColorValue => {
return {resource_paths: names};
};

export const ColorAndroidPrivate = (color: string): ColorValue => {
return {resource_paths: [color]};
};

export const normalizeColorObject = (
color: NativeColorValue,
): ?ProcessedColorValue => {
Expand Down
18 changes: 0 additions & 18 deletions Libraries/StyleSheet/PlatformColorValueTypesAndroid.android.js

This file was deleted.

17 changes: 0 additions & 17 deletions Libraries/StyleSheet/PlatformColorValueTypesAndroid.js

This file was deleted.

37 changes: 3 additions & 34 deletions RNTester/js/examples/PlatformColor/PlatformColorExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
const React = require('react');
const ReactNative = require('react-native');
import Platform from '../../../../Libraries/Utilities/Platform';
const {
ColorAndroid,
DynamicColorIOS,
PlatformColor,
StyleSheet,
Text,
View,
} = ReactNative;
const {DynamicColorIOS, PlatformColor, StyleSheet, Text, View} = ReactNative;

function PlatformColorsExample() {
function createTable() {
Expand Down Expand Up @@ -263,40 +256,22 @@ function DynamicColorsExample() {
);
}

function AndroidColorsExample() {
return Platform.OS === 'android' ? (
<View style={styles.column}>
<View style={styles.row}>
<Text style={styles.labelCell}>ColorAndroid('?attr/colorAccent')</Text>
<View
style={{
...styles.colorCell,
backgroundColor: ColorAndroid('?attr/colorAccent'),
}}
/>
</View>
</View>
) : (
<Text style={styles.labelCell}>Not applicable on this platform</Text>
);
}

function VariantColorsExample() {
return (
<View style={styles.column}>
<View style={styles.row}>
<Text style={styles.labelCell}>
{Platform.OS === 'ios'
? "DynamicColorIOS({light: 'red', dark: 'blue'})"
: "ColorAndroid('?attr/colorAccent')"}
: "PlatformColor('?attr/colorAccent')"}
</Text>
<View
style={{
...styles.colorCell,
backgroundColor:
Platform.OS === 'ios'
? DynamicColorIOS({light: 'red', dark: 'blue'})
: ColorAndroid('?attr/colorAccent'),
: PlatformColor('?attr/colorAccent'),
}}
/>
</View>
Expand Down Expand Up @@ -340,12 +315,6 @@ exports.examples = [
return <DynamicColorsExample />;
},
},
{
title: 'Android Colors',
render(): React.Element<any> {
return <AndroidColorsExample />;
},
},
{
title: 'Variant Colors',
render(): React.Element<any> {
Expand Down
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ import typeof Platform from './Libraries/Utilities/Platform';
import typeof processColor from './Libraries/StyleSheet/processColor';
import typeof {PlatformColor} from './Libraries/StyleSheet/PlatformColorValueTypes';
import typeof {DynamicColorIOS} from './Libraries/StyleSheet/PlatformColorValueTypesIOS';
import typeof {ColorAndroid} from './Libraries/StyleSheet/PlatformColorValueTypesAndroid';
import typeof RootTagContext from './Libraries/ReactNative/RootTagContext';
import typeof DeprecatedColorPropType from './Libraries/DeprecatedPropTypes/DeprecatedColorPropType';
import typeof DeprecatedEdgeInsetsPropType from './Libraries/DeprecatedPropTypes/DeprecatedEdgeInsetsPropType';
Expand Down Expand Up @@ -463,10 +462,6 @@ module.exports = {
return require('./Libraries/StyleSheet/PlatformColorValueTypesIOS')
.DynamicColorIOS;
},
get ColorAndroid(): ColorAndroid {
return require('./Libraries/StyleSheet/PlatformColorValueTypesAndroid')
.ColorAndroid;
},
get requireNativeComponent(): <T>(
uiViewClassName: string,
) => HostComponent<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ eslintTester.run('../platform-colors', rule, {
"const color = PlatformColor('controlAccentColor', 'controlColor');",
"const color = DynamicColorIOS({light: 'black', dark: 'white'});",
"const color = DynamicColorIOS({light: PlatformColor('black'), dark: PlatformColor('white')});",
"const color = ColorAndroid('?attr/colorAccent')",
],
invalid: [
{
Expand All @@ -49,14 +48,5 @@ eslintTester.run('../platform-colors', rule, {
"const white = 'white'; const color = DynamicColorIOS({light: 'black', dark: white});",
errors: [{message: rule.meta.messages.dynamicColorIOSDark}],
},
{
code: 'const color = ColorAndroid();',
errors: [{message: rule.meta.messages.colorAndroidArg}],
},
{
code:
"const colorAccent = '?attr/colorAccent'; const color = ColorAndroid(colorAccent);",
errors: [{message: rule.meta.messages.colorAndroidArg}],
},
],
});
13 changes: 1 addition & 12 deletions packages/eslint-plugin-react-native-community/platform-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
type: 'problem',
docs: {
description:
'Ensure that PlatformColor(), DynamicColorIOS(), and ColorAndroid() are passed literals of the expected shape.',
'Ensure that PlatformColor() and DynamicColorIOS() are passed literals of the expected shape.',
},
messages: {
platformColorArgsLength:
Expand All @@ -25,8 +25,6 @@ module.exports = {
'DynamicColorIOS() light value must be either a literal or a PlatformColor() call.',
dynamicColorIOSDark:
'DynamicColorIOS() dark value must be either a literal or a PlatformColor() call.',
colorAndroidArg:
'ColorAndroid() must take a single argument that is a literal.',
},
schema: [],
},
Expand Down Expand Up @@ -103,15 +101,6 @@ module.exports = {
});
return;
}
} else if (node.callee.name === 'ColorAndroid') {
const args = node.arguments;
if (!(args.length === 1 && args[0].type === 'Literal')) {
context.report({
node,
messageId: 'colorAndroidArg',
});
return;
}
}
},
};
Expand Down

0 comments on commit 411c344

Please sign in to comment.