All files / react-native-web/src/exports/StyleSheet flattenStyle.js

100% Statements 19/19
90% Branches 9/10
100% Functions 2/2
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                            685x 404x   281x       1304x 388x     916x 916x     916x 685x     231x 231x 575x 575x 569x 1811x 1811x       231x        
/**
 * Copyright (c) Nicolas Gallagher.
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */
 
import ReactNativePropRegistry from './ReactNativePropRegistry';
import invariant from 'fbjs/lib/invariant';
 
function getStyle(style) {
  if (typeof style === 'number') {
    return ReactNativePropRegistry.getByID(style);
  }
  return style;
}
 
function flattenStyle(style: ?any): ?Object {
  if (!style) {
    return undefined;
  }
 
  Eif (process.env.NODE_ENV !== 'production') {
    invariant(style !== true, 'style may be false but not true');
  }
 
  if (!Array.isArray(style)) {
    return getStyle(style);
  }
 
  const result = {};
  for (let i = 0, styleLength = style.length; i < styleLength; ++i) {
    const computedStyle = flattenStyle(style[i]);
    if (computedStyle) {
      for (const key in computedStyle) {
        const value = computedStyle[key];
        result[key] = value;
      }
    }
  }
  return result;
}
 
export default flattenStyle;