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.native.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import {
  3. TouchableHighlight,
  4. TouchableWithoutFeedback,
  5. View
  6. } from 'react-native';
  7. import AbstractContainer from './AbstractContainer';
  8. /**
  9. * Represents a container of React Native Component children with a style.
  10. *
  11. * @extends AbstractContainer
  12. */
  13. export class Container extends AbstractContainer {
  14. /**
  15. * Container component's property types.
  16. *
  17. * @static
  18. */
  19. static propTypes = AbstractContainer.propTypes
  20. /**
  21. * Implements React's {@link Component#render()}.
  22. *
  23. * @inheritdoc
  24. * @returns {ReactElement}
  25. */
  26. render() {
  27. // eslint-disable-next-line prefer-const
  28. let { onClick, style, touchFeedback, visible, ...props } = this.props;
  29. // visible
  30. if (typeof visible !== 'undefined' && !visible) {
  31. return null;
  32. }
  33. // onClick & touchFeedback
  34. (typeof touchFeedback === 'undefined') && (touchFeedback = onClick);
  35. const renderParent = touchFeedback || onClick;
  36. // eslint-disable-next-line object-property-newline
  37. let component = this._render(View, { ...props, style });
  38. if (renderParent) {
  39. const parentType
  40. = touchFeedback ? TouchableHighlight : TouchableWithoutFeedback;
  41. const parentProps = {};
  42. onClick && (parentProps.onPress = onClick);
  43. component = React.createElement(parentType, parentProps, component);
  44. }
  45. return component;
  46. }
  47. }