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';
|
|
|
|
|
2016-07-05 13:34:00 +00:00
|
|
|
var ReactNativePropRegistry = require('react/lib/ReactNativePropRegistry');
|
2016-03-02 12:27:13 +00:00
|
|
|
var invariant = require('fbjs/lib/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') {
|
2016-03-24 22:12:36 +00:00
|
|
|
return ReactNativePropRegistry.getByID(style);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
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 = {};
|
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;
|