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

Container.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* @flow */
  2. import React from 'react';
  3. import {
  4. TouchableHighlight,
  5. TouchableWithoutFeedback,
  6. View
  7. } from 'react-native';
  8. import AbstractContainer from '../AbstractContainer';
  9. /**
  10. * Represents a container of React Native/mobile {@link Component} children.
  11. *
  12. * @extends AbstractContainer
  13. */
  14. export default class Container extends AbstractContainer {
  15. /**
  16. * {@code Container} component's property types.
  17. *
  18. * @static
  19. */
  20. static propTypes = AbstractContainer.propTypes;
  21. /**
  22. * Implements React's {@link Component#render()}.
  23. *
  24. * @inheritdoc
  25. * @returns {ReactElement}
  26. */
  27. render() {
  28. // eslint-disable-next-line prefer-const
  29. let { onClick, style, touchFeedback, visible, ...props } = this.props;
  30. // onClick & touchFeedback
  31. (typeof touchFeedback === 'undefined') && (touchFeedback = onClick);
  32. // visible
  33. // The following property is responsible to hide/show this Container by
  34. // setting its size to 0. This will make the component not visible, but
  35. // it won't be destroyed, all its state is preserved. This is
  36. // intentional.
  37. // TODO: replace with display: 'none', supported in RN >= 0.43.
  38. const hidden = visible === false; // true / undefined
  39. if (hidden) {
  40. style = {
  41. ...style,
  42. height: 0,
  43. width: 0
  44. };
  45. }
  46. // eslint-disable-next-line object-property-newline
  47. let component = super._render(View, { ...props, style });
  48. if (!hidden && (touchFeedback || onClick)) {
  49. const parentType
  50. = touchFeedback ? TouchableHighlight : TouchableWithoutFeedback;
  51. const parentProps = {};
  52. onClick && (parentProps.onPress = onClick);
  53. component = React.createElement(parentType, parentProps, component);
  54. }
  55. return component;
  56. }
  57. }