// @flow import React, { PureComponent } from 'react'; import { Text, View } from 'react-native'; import { BottomSheet, hideDialog, isDialogOpen } from '../../base/dialog'; import { bottomSheetStyles } from '../../base/dialog/components/native/styles'; import { type Item } from '../../base/react/Types'; import { connect } from '../../base/redux'; import DeleteItemButton from './DeleteItemButton.native'; import ShowDialInInfoButton from './ShowDialInInfoButton.native'; import styles from './styles'; type Props = { /** * The Redux dispatch function. */ dispatch: Function, /** * Item being rendered in this menu. */ item: Item, /** * True if the menu is currently open, false otherwise. */ _isOpen: boolean } // eslint-disable-next-line prefer-const let RecentListItemMenu_; /** * Class to implement a popup menu that opens upon long pressing a recent list item. */ class RecentListItemMenu extends PureComponent { /** * Constructor of the component. * * @inheritdoc */ constructor(props: Props) { super(props); this._onCancel = this._onCancel.bind(this); this._renderMenuHeader = this._renderMenuHeader.bind(this); } /** * Implements {@code Component#render}. * * @inheritdoc */ render() { const { item } = this.props; const buttonProps = { afterClick: this._onCancel, itemId: item.id, showLabel: true, styles: bottomSheetStyles.buttons }; return ( ); } _onCancel: () => boolean; /** * Callback to hide this menu. * * @private * @returns {boolean} */ _onCancel() { if (this.props._isOpen) { this.props.dispatch(hideDialog(RecentListItemMenu_)); return true; } return false; } _renderMenuHeader: () => React$Element; /** * Function to render the menu's header. * * @returns {React$Element} */ _renderMenuHeader() { const { item } = this.props; return ( { item.title } ); } } /** * Function that maps parts of Redux state tree into component props. * * @param {Object} state - Redux state. * @private * @returns {Props} */ function _mapStateToProps(state) { return { _isOpen: isDialogOpen(state, RecentListItemMenu_) }; } RecentListItemMenu_ = connect(_mapStateToProps)(RecentListItemMenu); export default RecentListItemMenu_;