From 483b119aff5f3ce4e5b5f4577e0d8eb607f65f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 16 Feb 2023 14:48:05 +0100 Subject: [PATCH] wip: mini menu --- src/CONST.js | 19 +++++++ src/components/BaseMiniContextMenuItem.js | 47 ++++++++++++++++ src/components/ContextMenuItem.js | 36 ++++--------- .../Reactions/MiniQuickEmojiReactions.js | 53 +++++++++++++++++++ .../Reactions/QuickEmojiReactions.js | 24 +-------- .../report/ContextMenu/ContextMenuActions.js | 25 +++++++-- 6 files changed, 151 insertions(+), 53 deletions(-) create mode 100644 src/components/BaseMiniContextMenuItem.js create mode 100644 src/components/Reactions/MiniQuickEmojiReactions.js diff --git a/src/CONST.js b/src/CONST.js index 012a85f63829..0e388ee759ab 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -914,6 +914,25 @@ const CONST = { MAKE_REQUEST_WITH_SIDE_EFFECTS: 'makeRequestWithSideEffects', }, + QUICK_REACTIONS: [ + { + name: '+1', + code: '👍', + }, + { + name: 'heart', + code: '❤️', + }, + { + name: 'joy', + code: '😂', + }, + { + name: 'fire', + code: '🔥', + }, + ], + TFA_CODE_LENGTH: 6, CHAT_ATTACHMENT_TOKEN_KEY: 'X-Chat-Attachment-Token', diff --git a/src/components/BaseMiniContextMenuItem.js b/src/components/BaseMiniContextMenuItem.js new file mode 100644 index 000000000000..9f3981468bf5 --- /dev/null +++ b/src/components/BaseMiniContextMenuItem.js @@ -0,0 +1,47 @@ +import {Pressable, View} from 'react-native'; +import React from 'react'; +import PropTypes from 'prop-types'; +import _ from 'underscore'; +import styles from '../styles/styles'; +import * as StyleUtils from '../styles/StyleUtils'; +import getButtonState from '../libs/getButtonState'; +import variables from '../styles/variables'; +import Tooltip from './Tooltip'; + +const propTypes = { + tooltipText: PropTypes.string.isRequired, + onPress: PropTypes.func.isRequired, + children: PropTypes.oneOf([PropTypes.func, PropTypes.node]).isRequired, + isDelayButtonStateComplete: PropTypes.bool, +}; + +const defaultProps = { + isDelayButtonStateComplete: true, +}; + +const BaseMiniContextMenuItem = props => ( + + [ + styles.reportActionContextMenuMiniButton, + StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, props.isDelayButtonStateComplete)), + ] + } + > + {pressableState => ( + + {_.isFunction(props.children) ? props.children(pressableState) : props.children} + + )} + + +); + +BaseMiniContextMenuItem.propTypes = propTypes; +BaseMiniContextMenuItem.defaultProps = defaultProps; +BaseMiniContextMenuItem.displayName = 'BaseMiniContextMenuItem'; +export default BaseMiniContextMenuItem; diff --git a/src/components/ContextMenuItem.js b/src/components/ContextMenuItem.js index c87fc5e9b4c3..522baa846ac4 100644 --- a/src/components/ContextMenuItem.js +++ b/src/components/ContextMenuItem.js @@ -1,14 +1,12 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import {Pressable, View} from 'react-native'; import MenuItem from './MenuItem'; -import Tooltip from './Tooltip'; import Icon from './Icon'; import styles from '../styles/styles'; import * as StyleUtils from '../styles/StyleUtils'; import getButtonState from '../libs/getButtonState'; import withDelayToggleButtonState, {withDelayToggleButtonStatePropTypes} from './withDelayToggleButtonState'; -import variables from '../styles/variables'; +import BaseMiniContextMenuItem from './BaseMiniContextMenuItem'; const propTypes = { /** Icon Component */ @@ -75,29 +73,15 @@ class ContextMenuItem extends Component { return ( this.props.isMini ? ( - - [ - styles.reportActionContextMenuMiniButton, - StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, this.props.isDelayButtonStateComplete)), - ] - } - > - {({hovered, pressed}) => ( - - - - )} - - + + {({hovered, pressed}) => ( + + )} + ) : ( {}, +}; + +const MiniQuickEmojiReactions = props => ( + + {_.map(CONST.QUICK_REACTIONS, reaction => ( + props.onEmojiSelected(reaction)} + > + + {reaction.code} + + + ))} + {/* */} + +); + +MiniQuickEmojiReactions.displayName = 'MiniQuickEmojiReactions'; +MiniQuickEmojiReactions.propTypes = propTypes; +MiniQuickEmojiReactions.defaultProps = defaultProps; +export default MiniQuickEmojiReactions; diff --git a/src/components/Reactions/QuickEmojiReactions.js b/src/components/Reactions/QuickEmojiReactions.js index 14a4098ebde3..112af9bf0b61 100644 --- a/src/components/Reactions/QuickEmojiReactions.js +++ b/src/components/Reactions/QuickEmojiReactions.js @@ -4,36 +4,16 @@ import _ from 'underscore'; import PropTypes from 'prop-types'; import EmojiReactionBubble from './EmojiReactionBubble'; import AddReactionBubble from './AddReactionBubble'; - -const QUICK_REACTIONS = [ - { - name: '+1', - code: '👍', - }, - { - name: 'heart', - code: '❤️', - }, - { - name: 'joy', - code: '😂', - }, - { - name: 'fire', - code: '🔥', - }, -]; +import CONST from '../../CONST'; const EMOJI_BUBBLE_SCALE = 1.5; const propTypes = { - emojiIconRef: PropTypes.func, onEmojiSelected: PropTypes.func.isRequired, onPressOpenPicker: PropTypes.func, }; const defaultProps = { - emojiIconRef: () => {}, onPressOpenPicker: () => {}, }; @@ -46,7 +26,7 @@ const QuickEmojiReactions = props => ( justifyContent: 'space-between', }} > - {_.map(QUICK_REACTIONS, reaction => ( + {_.map(CONST.QUICK_REACTIONS, reaction => ( { + // TODO: we need to add the preferred skin tone here as well somehow + Report.toggleReaction(reportID, reportAction, emoji); + close(); + }; + + const isMini = !closePopover; + + if (isMini) { + return ( + + ); + } + return ( { - // TODO: we need to add the preferred skin tone here as well somehow - Report.toggleReaction(reportID, reportAction, emoji); - close(); - }} onPressOpenPicker={close} + onEmojiSelected={onEmojiSelected} /> ); },