選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

RecentListItemMenu.native.tsx 2.6KB

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