flattenStyle.js 889 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @flow strict-local
  8. * @format
  9. */
  10. 'use strict';
  11. import type {
  12. DangerouslyImpreciseStyle,
  13. DangerouslyImpreciseStyleProp,
  14. } from './StyleSheet';
  15. function flattenStyle(
  16. style: ?DangerouslyImpreciseStyleProp,
  17. ): ?DangerouslyImpreciseStyle {
  18. if (style === null || typeof style !== 'object') {
  19. return undefined;
  20. }
  21. if (!Array.isArray(style)) {
  22. return style;
  23. }
  24. const result = {};
  25. for (let i = 0, styleLength = style.length; i < styleLength; ++i) {
  26. const computedStyle = flattenStyle(style[i]);
  27. if (computedStyle) {
  28. for (const key in computedStyle) {
  29. result[key] = computedStyle[key];
  30. }
  31. }
  32. }
  33. return result;
  34. }
  35. module.exports = flattenStyle;