2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
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';
|
|
|
|
|
|
|
|
var StyleSheetRegistry = require('StyleSheetRegistry');
|
2015-03-25 02:34:12 +00:00
|
|
|
var invariant = require('invariant');
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-09-05 00:00:21 +00:00
|
|
|
import type { StyleObj } from 'StyleSheetTypes';
|
2015-03-25 02:34:12 +00:00
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
function getStyle(style) {
|
|
|
|
if (typeof style === 'number') {
|
|
|
|
return StyleSheetRegistry.getStyleByID(style);
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2015-06-08 20:44:32 +00:00
|
|
|
function flattenStyle(style: ?StyleObj): ?Object {
|
2015-01-30 01:10:49 +00:00
|
|
|
if (!style) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-25 02:34:12 +00:00
|
|
|
invariant(style !== true, 'style may be false but not true');
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
if (!Array.isArray(style)) {
|
|
|
|
return getStyle(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = {};
|
|
|
|
for (var i = 0; i < style.length; ++i) {
|
|
|
|
var computedStyle = flattenStyle(style[i]);
|
|
|
|
if (computedStyle) {
|
2015-06-08 20:44:32 +00:00
|
|
|
for (var key in computedStyle) {
|
|
|
|
result[key] = computedStyle[key];
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
var value = computedStyle[key];
|
|
|
|
}
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = flattenStyle;
|