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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. import type { Props } from '../AbstractContainer';
  10. /**
  11. * Represents a container of React Native/mobile {@link Component} children.
  12. *
  13. * @extends AbstractContainer
  14. */
  15. export default class Container<P: Props> extends AbstractContainer<P> {
  16. /**
  17. * Implements React's {@link Component#render()}.
  18. *
  19. * @inheritdoc
  20. * @returns {ReactElement}
  21. */
  22. render() {
  23. const {
  24. accessibilityLabel,
  25. accessible,
  26. onClick,
  27. touchFeedback = onClick,
  28. underlayColor,
  29. visible = true,
  30. ...props
  31. } = this.props;
  32. // visible
  33. if (!visible) {
  34. return null;
  35. }
  36. const onClickOrTouchFeedback = onClick || touchFeedback;
  37. let element
  38. = super._render(
  39. View,
  40. {
  41. pointerEvents: onClickOrTouchFeedback ? 'auto' : 'box-none',
  42. ...props
  43. });
  44. // onClick & touchFeedback
  45. if (element && onClickOrTouchFeedback) {
  46. element
  47. = React.createElement(
  48. touchFeedback
  49. ? TouchableHighlight
  50. : TouchableWithoutFeedback,
  51. {
  52. accessibilityLabel,
  53. accessible,
  54. onPress: onClick,
  55. underlayColor
  56. },
  57. element);
  58. }
  59. return element;
  60. }
  61. }