You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Container.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* @flow */
  2. import React from 'react';
  3. import {
  4. TouchableHighlight,
  5. TouchableWithoutFeedback,
  6. View
  7. } from 'react-native';
  8. import { Platform } from '../../';
  9. import AbstractContainer from '../AbstractContainer';
  10. /**
  11. * Represents a container of React Native/mobile {@link Component} children.
  12. *
  13. * @extends AbstractContainer
  14. */
  15. export default class Container extends AbstractContainer {
  16. /**
  17. * {@code Container} component's property types.
  18. *
  19. * @static
  20. */
  21. static propTypes = AbstractContainer.propTypes;
  22. /**
  23. * Implements React's {@link Component#render()}.
  24. *
  25. * @inheritdoc
  26. * @returns {ReactElement}
  27. */
  28. render() {
  29. const {
  30. onClick,
  31. touchFeedback = onClick,
  32. visible = true,
  33. ...props
  34. } = this.props;
  35. // visible
  36. if (!visible) {
  37. // FIXME: Whatever I try ends up failing somehow on Android, give up
  38. // for now, hoping display: 'none' solves this.
  39. if (Platform.OS === 'android') {
  40. return null;
  41. }
  42. // Intentionally hide this Container without destroying it.
  43. // TODO Replace with display: 'none' supported in RN >= 0.43.
  44. props.style = {
  45. ...props.style,
  46. height: 0,
  47. width: 0
  48. };
  49. }
  50. let element = super._render(View, props);
  51. // onClick & touchFeedback
  52. if (visible && (onClick || touchFeedback)) {
  53. element = React.createElement(
  54. touchFeedback ? TouchableHighlight : TouchableWithoutFeedback,
  55. { onPress: onClick },
  56. element
  57. );
  58. }
  59. return element;
  60. }
  61. }