2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
|
|
|
* @providesModule flattenStyle
|
2015-03-25 02:34:12 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2017-05-26 17:51:06 +00:00
|
|
|
var ReactNativePropRegistry;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2018-03-07 21:12:51 +00:00
|
|
|
import type {DangerouslyImpreciseStyleProp} from 'StyleSheet';
|
|
|
|
import type { Style } from 'StyleSheetTypes';
|
2015-03-25 02:34:12 +00:00
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
function getStyle(style) {
|
2017-05-26 17:51:06 +00:00
|
|
|
if (ReactNativePropRegistry === undefined) {
|
|
|
|
ReactNativePropRegistry = require('ReactNativePropRegistry');
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
if (typeof style === 'number') {
|
2016-03-24 22:12:36 +00:00
|
|
|
return ReactNativePropRegistry.getByID(style);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2018-03-07 21:12:51 +00:00
|
|
|
function flattenStyle(style: ?DangerouslyImpreciseStyleProp): ?Style {
|
2018-03-03 23:06:43 +00:00
|
|
|
if (style == null) {
|
2015-01-30 01:10:49 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Array.isArray(style)) {
|
2018-01-08 20:45:38 +00:00
|
|
|
/* $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. */
|
2015-01-30 01:10:49 +00:00
|
|
|
return getStyle(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = {};
|
2016-03-26 13:53:37 +00:00
|
|
|
for (var i = 0, styleLength = style.length; i < styleLength; ++i) {
|
2015-01-30 01:10:49 +00:00
|
|
|
var computedStyle = flattenStyle(style[i]);
|
|
|
|
if (computedStyle) {
|
2015-06-08 20:44:32 +00:00
|
|
|
for (var key in computedStyle) {
|
|
|
|
result[key] = computedStyle[key];
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = flattenStyle;
|