mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d3980dceab
Summary: Originally, normalizeColor.js was in Library/Color/ however, I noticed that its tests were in a completely different directly (Library/StyleSheet/__tests__) which was confusing. The other files such as processColor.js, setNormalizedAlphaColor.js had their tests in Library/StyleSheet/__tests__ as well. ## Changelog [Internal] [Changed] - Moved normalizeColor.js to a more appropriate directory where its tests live. Pull Request resolved: https://github.com/facebook/react-native/pull/27372 Test Plan: I simply moved a file and changed dependencies. The code should still function as is. Reviewed By: rickhanlonii, mdvacca Differential Revision: D18760210 Pulled By: yungsters fbshipit-source-id: 4c2400acabab35ccbb2533faa5c1d6487c9bf48e
42 lines
1.1 KiB
JavaScript
42 lines
1.1 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
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const Platform = require('../Utilities/Platform');
|
|
|
|
const normalizeColor = require('./normalizeColor');
|
|
|
|
/* eslint no-bitwise: 0 */
|
|
function processColor(color?: ?(string | number)): ?number {
|
|
if (color === undefined || color === null) {
|
|
return color;
|
|
}
|
|
|
|
let int32Color = normalizeColor(color);
|
|
if (int32Color === null || int32Color === undefined) {
|
|
return undefined;
|
|
}
|
|
|
|
// Converts 0xrrggbbaa into 0xaarrggbb
|
|
int32Color = ((int32Color << 24) | (int32Color >>> 8)) >>> 0;
|
|
|
|
if (Platform.OS === 'android') {
|
|
// Android use 32 bit *signed* integer to represent the color
|
|
// We utilize the fact that bitwise operations in JS also operates on
|
|
// signed 32 bit integers, so that we can use those to convert from
|
|
// *unsigned* to *signed* 32bit int that way.
|
|
int32Color = int32Color | 0x0;
|
|
}
|
|
return int32Color;
|
|
}
|
|
|
|
module.exports = processColor;
|