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.

RecentListItemMenu.native.js 3.4KB

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