ReactNativeStyleAttributes.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 strict-local
  8. * @flow
  9. */
  10. 'use strict';
  11. const DeprecatedImageStylePropTypes = require('../../DeprecatedPropTypes/DeprecatedImageStylePropTypes');
  12. const DeprecatedTextStylePropTypes = require('../../DeprecatedPropTypes/DeprecatedTextStylePropTypes');
  13. const DeprecatedViewStylePropTypes = require('../../DeprecatedPropTypes/DeprecatedViewStylePropTypes');
  14. const processColor = require('../../StyleSheet/processColor');
  15. const processTransform = require('../../StyleSheet/processTransform');
  16. const sizesDiffer = require('../../Utilities/differ/sizesDiffer');
  17. type ReturnBoolType = <V>(V) => true;
  18. type BoolifiedDeprecatedViewStylePropTypes = $ObjMap<
  19. typeof DeprecatedViewStylePropTypes,
  20. ReturnBoolType,
  21. >;
  22. type BoolifiedDeprecatedTextStylePropTypes = $ObjMapi<
  23. typeof DeprecatedTextStylePropTypes,
  24. ReturnBoolType,
  25. >;
  26. type BoolifiedDeprecatedImageStylePropTypes = $ObjMapi<
  27. typeof DeprecatedImageStylePropTypes,
  28. ReturnBoolType,
  29. >;
  30. type StyleAttributesType = {
  31. ...BoolifiedDeprecatedViewStylePropTypes,
  32. ...BoolifiedDeprecatedTextStylePropTypes,
  33. ...BoolifiedDeprecatedImageStylePropTypes,
  34. transform: $ReadOnly<{|process: typeof processTransform|}> | true,
  35. shadowOffset: $ReadOnly<{|diff: typeof sizesDiffer|}> | true,
  36. backgroundColor: typeof colorAttributes | true,
  37. borderBottomColor: typeof colorAttributes | true,
  38. borderColor: typeof colorAttributes | true,
  39. borderLeftColor: typeof colorAttributes | true,
  40. borderRightColor: typeof colorAttributes | true,
  41. borderTopColor: typeof colorAttributes | true,
  42. borderStartColor: typeof colorAttributes | true,
  43. borderEndColor: typeof colorAttributes | true,
  44. color: typeof colorAttributes | true,
  45. shadowColor: typeof colorAttributes | true,
  46. textDecorationColor: typeof colorAttributes | true,
  47. tintColor: typeof colorAttributes | true,
  48. textShadowColor: typeof colorAttributes | true,
  49. overlayColor: typeof colorAttributes | true,
  50. ...
  51. };
  52. const ReactNativeStyleAttributes: StyleAttributesType = {};
  53. for (const attributeName of Object.keys({
  54. ...DeprecatedViewStylePropTypes,
  55. ...DeprecatedTextStylePropTypes,
  56. ...DeprecatedImageStylePropTypes,
  57. })) {
  58. ReactNativeStyleAttributes[attributeName] = true;
  59. }
  60. ReactNativeStyleAttributes.transform = {process: processTransform};
  61. ReactNativeStyleAttributes.shadowOffset = {diff: sizesDiffer};
  62. const colorAttributes = {process: processColor};
  63. ReactNativeStyleAttributes.backgroundColor = colorAttributes;
  64. ReactNativeStyleAttributes.borderBottomColor = colorAttributes;
  65. ReactNativeStyleAttributes.borderColor = colorAttributes;
  66. ReactNativeStyleAttributes.borderLeftColor = colorAttributes;
  67. ReactNativeStyleAttributes.borderRightColor = colorAttributes;
  68. ReactNativeStyleAttributes.borderTopColor = colorAttributes;
  69. ReactNativeStyleAttributes.borderStartColor = colorAttributes;
  70. ReactNativeStyleAttributes.borderEndColor = colorAttributes;
  71. ReactNativeStyleAttributes.color = colorAttributes;
  72. ReactNativeStyleAttributes.shadowColor = colorAttributes;
  73. ReactNativeStyleAttributes.textDecorationColor = colorAttributes;
  74. ReactNativeStyleAttributes.tintColor = colorAttributes;
  75. ReactNativeStyleAttributes.textShadowColor = colorAttributes;
  76. ReactNativeStyleAttributes.overlayColor = colorAttributes;
  77. module.exports = ReactNativeStyleAttributes;