Add support for number as colors

Summary: Closes https://github.com/facebook/react-native/pull/5805

Reviewed By: svcscm

Differential Revision: D2911330

Pulled By: javache

fb-gh-sync-id: b07c00a9271a161e3c88755434f6ffa34f4d519d
This commit is contained in:
Christopher Chedeau
2016-02-08 04:04:01 -08:00
committed by facebook-github-bot-7
parent 90403154a2
commit 1c112762e3
4 changed files with 42 additions and 22 deletions

View File

@@ -12,12 +12,19 @@
/* eslint no-bitwise: 0 */
'use strict';
function normalizeColor(color: string): ?number {
function normalizeColor(color: string | number): ?number {
var match;
if (typeof color === 'number') {
if (color >>> 0 === color && color >= 0 && color <= 0xffffffff) {
return color;
}
return null;
}
// Ordered based on occurrences on Facebook codebase
if ((match = matchers.hex6.exec(color))) {
return (parseInt(match[1], 16) << 8 | 0x000000ff) >>> 0;
return parseInt(match[1] + 'ff', 16) >>> 0;
}
if (names.hasOwnProperty(color)) {