Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RecentListItemMenu.native.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { Text, View } from 'react-native';
  4. import { BottomSheet, hideDialog, isDialogOpen } from '../../base/dialog';
  5. import { bottomSheetStyles } from '../../base/dialog/components/native/styles';
  6. import { type Item } from '../../base/react/Types';
  7. import { connect } from '../../base/redux';
  8. import DeleteItemButton from './DeleteItemButton.native';
  9. import ShowDialInInfoButton from './ShowDialInInfoButton.native';
  10. import styles from './styles';
  11. type Props = {
  12. /**
  13. * The Redux dispatch function.
  14. */
  15. dispatch: Function,
  16. /**
  17. * Item being rendered in this menu.
  18. */
  19. item: Item,
  20. /**
  21. * True if the menu is currently open, false otherwise.
  22. */
  23. _isOpen: boolean
  24. }
  25. // eslint-disable-next-line prefer-const
  26. let RecentListItemMenu_;
  27. /**
  28. * Class to implement a popup menu that opens upon long pressing a recent list item.
  29. */
  30. class RecentListItemMenu extends PureComponent<Props> {
  31. /**
  32. * Constructor of the component.
  33. *
  34. * @inheritdoc
  35. */
  36. constructor(props: Props) {
  37. super(props);
  38. this._onCancel = this._onCancel.bind(this);
  39. this._renderMenuHeader = this._renderMenuHeader.bind(this);
  40. }
  41. /**
  42. * Implements {@code Component#render}.
  43. *
  44. * @inheritdoc
  45. */
  46. render() {
  47. const { item } = this.props;
  48. const buttonProps = {
  49. afterClick: this._onCancel,
  50. itemId: item.id,
  51. showLabel: true,
  52. styles: bottomSheetStyles.buttons
  53. };
  54. return (
  55. <BottomSheet
  56. onCancel = { this._onCancel }
  57. renderHeader = { this._renderMenuHeader }>
  58. <DeleteItemButton { ...buttonProps } />
  59. <ShowDialInInfoButton { ...buttonProps } />
  60. </BottomSheet>
  61. );
  62. }
  63. _onCancel: () => boolean;
  64. /**
  65. * Callback to hide this menu.
  66. *
  67. * @private
  68. * @returns {boolean}
  69. */
  70. _onCancel() {
  71. if (this.props._isOpen) {
  72. this.props.dispatch(hideDialog(RecentListItemMenu_));
  73. return true;
  74. }
  75. return false;
  76. }
  77. _renderMenuHeader: () => React$Element<any>;
  78. /**
  79. * Function to render the menu's header.
  80. *
  81. * @returns {React$Element}
  82. */
  83. _renderMenuHeader() {
  84. const { item } = this.props;
  85. return (
  86. <View
  87. style = { [
  88. bottomSheetStyles.sheet,
  89. styles.entryNameContainer
  90. ] }>
  91. <Text
  92. ellipsizeMode = { 'middle' }
  93. numberOfLines = { 1 }
  94. style = { styles.entryNameLabel }>
  95. { item.title }
  96. </Text>
  97. </View>
  98. );
  99. }
  100. }
  101. /**
  102. * Function that maps parts of Redux state tree into component props.
  103. *
  104. * @param {Object} state - Redux state.
  105. * @private
  106. * @returns {Props}
  107. */
  108. function _mapStateToProps(state) {
  109. return {
  110. _isOpen: isDialogOpen(state, RecentListItemMenu_)
  111. };
  112. }
  113. RecentListItemMenu_ = connect(_mapStateToProps)(RecentListItemMenu);
  114. export default RecentListItemMenu_;