mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
dbe0d7d4b5
Summary: The [PlatformColor PR](https://github.com/facebook/react-native/pull/27908) is currently open to implement the [PlatformColor proposal](react-native-community/discussions-and-proposals#126). When that PR was imported into Facebooks internal builds it was found that the change to the `processColor()` function to return an opaque type or `number` instead of just `number` breaks internal components. This PR is a simplification of the PlatformColor PR only changing the return type of `processColor()` from `?number` to `?number | NativeColorType` where `NativeColorType` is just an empty but opaque type. This will allow changes to be made to these internal components but with less risk than the larger PR. ## Changelog [General] [Changed] - Add NativeColorType opaque type to normalizeColor() ahead of PlatformColor PR Pull Request resolved: https://github.com/facebook/react-native/pull/28040 Test Plan: Flow checks, Jest test, iOS unit tests, iOS integration tests, and manual testing performed on RNTester for iOS and Android. Differential Revision: D19860205 Pulled By: TheSavior fbshipit-source-id: 799662c6621d3974158b375ccccfa136982c43b4
49 lines
1.5 KiB
JavaScript
49 lines
1.5 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');
|
|
|
|
// TODO: This is an empty object for now, just to enforce that everything using this
|
|
// downstream is correct. This will be replaced with an import to other files
|
|
// with a platform specific implementation. See the PR for more information
|
|
// https://github.com/facebook/react-native/pull/27908
|
|
opaque type NativeColorType = {};
|
|
export type ProcessedColorValue = ?number | NativeColorType;
|
|
|
|
/* eslint no-bitwise: 0 */
|
|
function processColor(color?: ?(string | number)): ProcessedColorValue {
|
|
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;
|