react-native/Libraries/StyleSheet/flattenStyle.js

42 lines
893 B
JavaScript
Raw Normal View History

2015-01-30 01:10:49 +00:00
/**
* 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.
2015-01-30 01:10:49 +00:00
*
* @providesModule flattenStyle
2015-03-25 02:34:12 +00:00
* @flow
* @format
2015-01-30 01:10:49 +00:00
*/
'use strict';
import type {
DangerouslyImpreciseStyle,
DangerouslyImpreciseStyleProp,
} from 'StyleSheet';
2015-03-25 02:34:12 +00:00
function flattenStyle(
style: ?DangerouslyImpreciseStyleProp,
): ?DangerouslyImpreciseStyle {
if (style === null || typeof style !== 'object') {
2015-01-30 01:10:49 +00:00
return undefined;
}
if (!Array.isArray(style)) {
return style;
2015-01-30 01:10:49 +00:00
}
var result = {};
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) {
for (var key in computedStyle) {
result[key] = computedStyle[key];
}
2015-01-30 01:10:49 +00:00
}
}
return result;
}
module.exports = flattenStyle;