mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
b98bf1e097
Summary: These types were polymorphic so that stricter types could be passed in for dimension or color. For example, color could be a union of allowed colors. However, since `rgb(0,0,0)` is a valid color, these would have to be allowed opaque types and every creator or caller of these colors would have to use a function. This would require a massive change to every RN product in the world for negligable gain because StyleSheet values are validated at dev at runtime and cause redboxes for invalid uses. Since we don't plan to adopt these widely, lets clean up the complexity of these types. Reviewed By: sahrens Differential Revision: D7158920 fbshipit-source-id: c58ae402c8248b0863c217c27153191a49c6b980
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @providesModule flattenStyle
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
var ReactNativePropRegistry;
|
|
|
|
import type { StyleProp, Style } from 'StyleSheetTypes';
|
|
|
|
function getStyle(style) {
|
|
if (ReactNativePropRegistry === undefined) {
|
|
ReactNativePropRegistry = require('ReactNativePropRegistry');
|
|
}
|
|
if (typeof style === 'number') {
|
|
return ReactNativePropRegistry.getByID(style);
|
|
}
|
|
return style;
|
|
}
|
|
|
|
function flattenStyle(style: ?StyleProp<Style>): ?Style {
|
|
if (style == null) {
|
|
return undefined;
|
|
}
|
|
|
|
if (!Array.isArray(style)) {
|
|
/* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
|
|
* error found when Flow v0.63 was deployed. To see the error delete this
|
|
* comment and run Flow. */
|
|
return getStyle(style);
|
|
}
|
|
|
|
var result = {};
|
|
for (var i = 0, styleLength = style.length; i < styleLength; ++i) {
|
|
var computedStyle = flattenStyle(style[i]);
|
|
if (computedStyle) {
|
|
for (var key in computedStyle) {
|
|
result[key] = computedStyle[key];
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
module.exports = flattenStyle;
|