splitLayoutProps.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. * @format
  8. * @flow strict-local
  9. */
  10. 'use strict';
  11. import type {DangerouslyImpreciseStyle} from './StyleSheet';
  12. const OUTER_PROPS = Object.assign(Object.create(null), {
  13. margin: true,
  14. marginHorizontal: true,
  15. marginVertical: true,
  16. marginBottom: true,
  17. marginTop: true,
  18. marginLeft: true,
  19. marginRight: true,
  20. flex: true,
  21. flexGrow: true,
  22. flexShrink: true,
  23. flexBasis: true,
  24. alignSelf: true,
  25. height: true,
  26. minHeight: true,
  27. maxHeight: true,
  28. width: true,
  29. minWidth: true,
  30. maxWidth: true,
  31. position: true,
  32. left: true,
  33. right: true,
  34. bottom: true,
  35. top: true,
  36. transform: true,
  37. });
  38. function splitLayoutProps(
  39. props: ?DangerouslyImpreciseStyle,
  40. ): {
  41. outer: DangerouslyImpreciseStyle,
  42. inner: DangerouslyImpreciseStyle,
  43. ...
  44. } {
  45. const inner = {};
  46. const outer = {};
  47. if (props) {
  48. Object.keys(props).forEach(k => {
  49. const value: $ElementType<DangerouslyImpreciseStyle, typeof k> = props[k];
  50. if (OUTER_PROPS[k]) {
  51. outer[k] = value;
  52. } else {
  53. inner[k] = value;
  54. }
  55. });
  56. }
  57. return {outer, inner};
  58. }
  59. module.exports = splitLayoutProps;