Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AbstractContainer.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { getFixedPlatformStyle } from '../../styles';
  4. /**
  5. * {@code AbstractContainer} component's property types.
  6. */
  7. export type Props = {
  8. /**
  9. * An optional accessibility label to apply to the container root.
  10. */
  11. accessibilityLabel?: string,
  12. /**
  13. * Whether or not this element is an accessibility element.
  14. */
  15. accessible?: boolean,
  16. /**
  17. * React Elements to display within the component.
  18. */
  19. children: React$Node,
  20. /**
  21. * Class names of the component (for web).
  22. */
  23. className?: string,
  24. /**
  25. * The event handler/listener to be invoked when this
  26. * {@code AbstractContainer} is clicked on Web or pressed on React
  27. * Native. If {@code onClick} is defined and {@link touchFeedback} is
  28. * undefined, {@code touchFeedback} is considered defined as
  29. * {@code true}.
  30. */
  31. onClick?: ?Function,
  32. /**
  33. * The style (as in stylesheet) to be applied to this
  34. * {@code AbstractContainer}.
  35. */
  36. style?: Array<?string> | Object,
  37. /**
  38. * If this instance is to provide visual feedback when touched, then
  39. * {@code true}; otherwise, {@code false}. If {@code touchFeedback} is
  40. * undefined and {@link onClick} is defined, {@code touchFeedback} is
  41. * considered defined as {@code true}.
  42. */
  43. touchFeedback?: ?Function,
  44. /**
  45. * Color to display when clicked.
  46. */
  47. underlayColor?: string,
  48. /**
  49. * If this {@code AbstractContainer} is to be visible, then {@code true}
  50. * or {@code false} if this instance is to be hidden or not rendered at
  51. * all.
  52. */
  53. visible?: ?boolean
  54. };
  55. /**
  56. * Abstract (base) class for container of React {@link Component} children with
  57. * a style.
  58. *
  59. * @extends Component
  60. */
  61. export default class AbstractContainer<P: Props> extends Component<P> {
  62. /**
  63. * Renders this {@code AbstractContainer} as a React {@code Component} of a
  64. * specific type.
  65. *
  66. * @param {string|ReactClass} type - The type of the React {@code Component}
  67. * which is to be rendered.
  68. * @param {Object|undefined} props - The read-only React {@code Component}
  69. * properties, if any, to render. If undefined, the props of this instance
  70. * will be rendered.
  71. * @protected
  72. * @returns {ReactElement}
  73. */
  74. _render(type, props?: P) {
  75. const {
  76. children,
  77. style,
  78. /* eslint-disable no-unused-vars */
  79. // The following properties are defined for the benefit of
  80. // AbstractContainer and its extenders so they are to not be
  81. // propagated.
  82. touchFeedback,
  83. visible,
  84. /* eslint-enable no-unused-vars */
  85. ...filteredProps
  86. } = props || this.props;
  87. const _style = getFixedPlatformStyle(style);
  88. // $FlowFixMe
  89. return React.createElement(type, {
  90. style: _style,
  91. ...filteredProps
  92. }, children);
  93. }
  94. }