Skip to content

Commit

Permalink
wip: mini menu
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Feb 16, 2023
1 parent 8042b9b commit 483b119
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 53 deletions.
19 changes: 19 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
47 changes: 47 additions & 0 deletions src/components/BaseMiniContextMenuItem.js
Original file line number Diff line number Diff line change
@@ -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 => (
<Tooltip text={props.tooltipText}>
<Pressable
focusable
onPress={props.onPress}
accessibilityLabel={props.tooltipText}
style={
({hovered, pressed}) => [
styles.reportActionContextMenuMiniButton,
StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, props.isDelayButtonStateComplete)),
]
}
>
{pressableState => (
<View style={[StyleUtils.getWidthAndHeightStyle(variables.iconSizeNormal), styles.alignItemsCenter, styles.justifyContentCenter]}>
{_.isFunction(props.children) ? props.children(pressableState) : props.children}
</View>
)}
</Pressable>
</Tooltip>
);

BaseMiniContextMenuItem.propTypes = propTypes;
BaseMiniContextMenuItem.defaultProps = defaultProps;
BaseMiniContextMenuItem.displayName = 'BaseMiniContextMenuItem';
export default BaseMiniContextMenuItem;
36 changes: 10 additions & 26 deletions src/components/ContextMenuItem.js
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -75,29 +73,15 @@ class ContextMenuItem extends Component {
return (
this.props.isMini
? (
<Tooltip text={text}>
<Pressable
focusable
accessibilityLabel={text}
onPress={this.triggerPressAndUpdateSuccess}
style={
({hovered, pressed}) => [
styles.reportActionContextMenuMiniButton,
StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, this.props.isDelayButtonStateComplete)),
]
}
>
{({hovered, pressed}) => (
<View style={[StyleUtils.getWidthAndHeightStyle(variables.iconSizeNormal), styles.alignItemsCenter, styles.justifyContentCenter]}>
<Icon
small
src={icon}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed, this.props.isDelayButtonStateComplete))}
/>
</View>
)}
</Pressable>
</Tooltip>
<BaseMiniContextMenuItem tooltipText={text} onPress={this.triggerPressAndUpdateSuccess}>
{({hovered, pressed}) => (
<Icon
small
src={icon}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed, this.props.isDelayButtonStateComplete))}
/>
)}
</BaseMiniContextMenuItem>
) : (
<MenuItem
title={text}
Expand Down
53 changes: 53 additions & 0 deletions src/components/Reactions/MiniQuickEmojiReactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import PropTypes from 'prop-types';
import CONST from '../../CONST';
import styles from '../../styles/styles';
import Text from '../Text';
import * as StyleUtils from '../../styles/StyleUtils';
import BaseMiniContextMenuItem from '../BaseMiniContextMenuItem';

const propTypes = {
onEmojiSelected: PropTypes.func.isRequired,
onPressOpenPicker: PropTypes.func,
};

const defaultProps = {
onPressOpenPicker: () => {},
};

const MiniQuickEmojiReactions = props => (
<View style={{
flexDirection: 'row',
}}
>
{_.map(CONST.QUICK_REACTIONS, reaction => (
<BaseMiniContextMenuItem
key={reaction.name}
isDelayButtonStateComplete={false}
tooltipText={`:${reaction.name}:`}
onPress={() => props.onEmojiSelected(reaction)}
>
<Text style={[
styles.emojiReactionText,
StyleUtils.getEmojiReactionTextStyle(1.3),
]}
>
{reaction.code}
</Text>
</BaseMiniContextMenuItem>
))}
{/* <AddReactionBubble */}
{/* iconSizeScale={1.2} */}
{/* sizeScale={EMOJI_BUBBLE_SCALE} */}
{/* onSelectEmoji={props.onEmojiSelected} */}
{/* onPressOpenPicker={props.onPressOpenPicker} */}
{/* /> */}
</View>
);

MiniQuickEmojiReactions.displayName = 'MiniQuickEmojiReactions';
MiniQuickEmojiReactions.propTypes = propTypes;
MiniQuickEmojiReactions.defaultProps = defaultProps;
export default MiniQuickEmojiReactions;
24 changes: 2 additions & 22 deletions src/components/Reactions/QuickEmojiReactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {},
};

Expand All @@ -46,7 +26,7 @@ const QuickEmojiReactions = props => (
justifyContent: 'space-between',
}}
>
{_.map(QUICK_REACTIONS, reaction => (
{_.map(CONST.QUICK_REACTIONS, reaction => (
<EmojiReactionBubble
key={reaction.name}
emojiName={reaction.name}
Expand Down
25 changes: 20 additions & 5 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as ContextMenuUtils from './ContextMenuUtils';
import * as Environment from '../../../../libs/Environment/Environment';
import Permissions from '../../../../libs/Permissions';
import QuickEmojiReactions from '../../../../components/Reactions/QuickEmojiReactions';
import MiniQuickEmojiReactions from '../../../../components/Reactions/MiniQuickEmojiReactions';

/**
* Gets the HTML version of the message in an action.
Expand Down Expand Up @@ -47,15 +48,29 @@ export default [
hideContextMenu(false);
};

const onEmojiSelected = (emoji) => {
// 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 (
<MiniQuickEmojiReactions
key="MiniQuickEmojiReactions"
onPressOpenPicker={close}
onEmojiSelected={onEmojiSelected}
/>
);
}

return (
<QuickEmojiReactions
key="QuickEmojiReactions"
onEmojiSelected={(emoji) => {
// TODO: we need to add the preferred skin tone here as well somehow
Report.toggleReaction(reportID, reportAction, emoji);
close();
}}
onPressOpenPicker={close}
onEmojiSelected={onEmojiSelected}
/>
);
},
Expand Down

0 comments on commit 483b119

Please sign in to comment.