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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. const {
  29. accessibilityLabel,
  30. accessible,
  31. onClick,
  32. touchFeedback = onClick,
  33. visible = true,
  34. ...props
  35. } = this.props;
  36. // visible
  37. if (!visible) {
  38. return null;
  39. }
  40. const onClickOrTouchFeedback = onClick || touchFeedback;
  41. let element
  42. = super._render(
  43. View,
  44. {
  45. pointerEvents: onClickOrTouchFeedback ? 'auto' : 'box-none',
  46. ...props
  47. });
  48. // onClick & touchFeedback
  49. if (element && onClickOrTouchFeedback) {
  50. element
  51. = React.createElement(
  52. touchFeedback
  53. ? TouchableHighlight
  54. : TouchableWithoutFeedback,
  55. {
  56. accessibilityLabel,
  57. accessible,
  58. onPress: onClick
  59. },
  60. element);
  61. }
  62. return element;
  63. }
  64. }