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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React, { PureComponent } from 'react';
  2. import { Text, View } from 'react-native';
  3. import { BottomSheet, hideSheet } from '../../base/dialog';
  4. import { bottomSheetStyles } from '../../base/dialog/components/native/styles';
  5. import { type Item } from '../../base/react/Types';
  6. import { connect } from '../../base/redux';
  7. import DeleteItemButton from './DeleteItemButton.native';
  8. import ShowDialInInfoButton from './ShowDialInInfoButton.native';
  9. import styles from './styles';
  10. type Props = {
  11. /**
  12. * The Redux dispatch function.
  13. */
  14. dispatch: Function,
  15. /**
  16. * Item being rendered in this menu.
  17. */
  18. item: Item
  19. }
  20. /**
  21. * Class to implement a popup menu that opens upon long pressing a recent list item.
  22. */
  23. class RecentListItemMenu extends PureComponent<Props> {
  24. /**
  25. * Constructor of the component.
  26. *
  27. * @inheritdoc
  28. */
  29. constructor(props: Props) {
  30. super(props);
  31. this._onCancel = this._onCancel.bind(this);
  32. this._renderMenuHeader = this._renderMenuHeader.bind(this);
  33. }
  34. /**
  35. * Implements {@code Component#render}.
  36. *
  37. * @inheritdoc
  38. */
  39. render() {
  40. const { item } = this.props;
  41. const buttonProps = {
  42. afterClick: this._onCancel,
  43. itemId: item.id,
  44. showLabel: true,
  45. styles: bottomSheetStyles.buttons
  46. };
  47. return (
  48. <BottomSheet
  49. renderHeader = { this._renderMenuHeader }>
  50. <DeleteItemButton { ...buttonProps } />
  51. <ShowDialInInfoButton { ...buttonProps } />
  52. </BottomSheet>
  53. );
  54. }
  55. /**
  56. * Callback to hide this menu.
  57. *
  58. * @private
  59. * @returns {boolean}
  60. */
  61. _onCancel() {
  62. this.props.dispatch(hideSheet());
  63. }
  64. /**
  65. * Function to render the menu's header.
  66. *
  67. * @returns {React$Element}
  68. */
  69. _renderMenuHeader() {
  70. const { item } = this.props;
  71. return (
  72. <View
  73. style = { [
  74. bottomSheetStyles.sheet,
  75. styles.entryNameContainer
  76. ] }>
  77. <Text
  78. ellipsizeMode = { 'middle' }
  79. numberOfLines = { 1 }
  80. style = { styles.entryNameLabel }>
  81. { item.title }
  82. </Text>
  83. </View>
  84. );
  85. }
  86. }
  87. export default connect()(RecentListItemMenu);