Files
react-native/packages/eslint-plugin-react-native-community/platform-colors.js
T
Tom Underhill 411c344794 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](https://github.com/facebook/react-native/pull/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: https://github.com/facebook/react-native/pull/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
2020-04-09 18:40:31 -07:00

109 lines
3.2 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
module.exports = {
meta: {
type: 'problem',
docs: {
description:
'Ensure that PlatformColor() and DynamicColorIOS() are passed literals of the expected shape.',
},
messages: {
platformColorArgsLength:
'PlatformColor() must have at least one argument that is a literal.',
platformColorArgTypes:
'PlatformColor() every argument must be a literal.',
dynamicColorIOSArg:
'DynamicColorIOS() must take a single argument of type Object containing two keys: light and dark.',
dynamicColorIOSLight:
'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.',
},
schema: [],
},
create: function(context) {
return {
CallExpression: function(node) {
if (node.callee.name === 'PlatformColor') {
const args = node.arguments;
if (args.length === 0) {
context.report({
node,
messageId: 'platformColorArgsLength',
});
return;
}
if (!args.every(arg => arg.type === 'Literal')) {
context.report({
node,
messageId: 'platformColorArgTypes',
});
return;
}
} else if (node.callee.name === 'DynamicColorIOS') {
const args = node.arguments;
if (!(args.length === 1 && args[0].type === 'ObjectExpression')) {
context.report({
node,
messageId: 'dynamicColorIOSArg',
});
return;
}
const properties = args[0].properties;
if (
!(
properties.length === 2 &&
properties[0].type === 'Property' &&
properties[0].key.name === 'light' &&
properties[1].type === 'Property' &&
properties[1].key.name === 'dark'
)
) {
context.report({
node,
messageId: 'dynamicColorIOSArg',
});
return;
}
const light = properties[0];
if (
!(
light.value.type === 'Literal' ||
(light.value.type === 'CallExpression' &&
light.value.callee.name === 'PlatformColor')
)
) {
context.report({
node,
messageId: 'dynamicColorIOSLight',
});
return;
}
const dark = properties[1];
if (
!(
dark.value.type === 'Literal' ||
(dark.value.type === 'CallExpression' &&
dark.value.callee.name === 'PlatformColor')
)
) {
context.report({
node,
messageId: 'dynamicColorIOSDark',
});
return;
}
}
},
};
},
};