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 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React from 'react';
  2. import {
  3. Dimensions,
  4. TouchableHighlight,
  5. TouchableWithoutFeedback,
  6. View
  7. } from 'react-native';
  8. import AbstractContainer from './AbstractContainer';
  9. /**
  10. * Represents a container of React Native Component children with a style.
  11. *
  12. * @extends AbstractContainer
  13. */
  14. export class Container extends AbstractContainer {
  15. /**
  16. * Implements React's {@link Component#render()}.
  17. *
  18. * @inheritdoc
  19. * @returns {ReactElement}
  20. */
  21. render() {
  22. // eslint-disable-next-line prefer-const
  23. let { onClick, style, touchFeedback, visible, ...props } = this.props;
  24. // visible
  25. // The following property is responsible to hide/show this Container by
  26. // moving it out of site of the screen boundaries. An attempt to use the
  27. // opacity property was made in order to eventually implement a
  28. // fadeIn/fadeOut animation, however a known React Native problem was
  29. // discovered, which allows the view to still capture touch events even
  30. // if hidden.
  31. // TODO Alternatives will be investigated.
  32. let parentStyle;
  33. if (typeof visible !== 'undefined' && !visible) {
  34. const windowDimensions = Dimensions.get('window');
  35. parentStyle = {
  36. bottom: -windowDimensions.height,
  37. right: -windowDimensions.width
  38. };
  39. }
  40. // onClick & touchFeedback
  41. (typeof touchFeedback === 'undefined') && (touchFeedback = onClick);
  42. const renderParent = touchFeedback || onClick;
  43. if (!renderParent && parentStyle) {
  44. style = {
  45. ...style,
  46. ...parentStyle
  47. };
  48. }
  49. // eslint-disable-next-line object-property-newline
  50. let component = this._render(View, { ...props, style });
  51. if (renderParent) {
  52. const parentType
  53. = touchFeedback ? TouchableHighlight : TouchableWithoutFeedback;
  54. const parentProps = {};
  55. onClick && (parentProps.onPress = onClick);
  56. parentStyle && (parentProps.style = parentStyle);
  57. component = React.createElement(parentType, parentProps, component);
  58. }
  59. return component;
  60. }
  61. }
  62. /**
  63. * Container component's property types.
  64. *
  65. * @static
  66. */
  67. Container.propTypes = AbstractContainer.propTypes;