-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: render quick reactions in context menu
- Loading branch information
Showing
9 changed files
with
325 additions
and
20 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import {Pressable, View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import Tooltip from '../Tooltip'; | ||
import styles from '../../styles/styles'; | ||
import * as StyleUtils from '../../styles/StyleUtils'; | ||
import Icon from '../Icon'; | ||
import * as Expensicons from '../Icon/Expensicons'; | ||
import Text from '../Text'; | ||
import getButtonState from '../../libs/getButtonState'; | ||
import * as EmojiPickerAction from '../../libs/actions/EmojiPickerAction'; | ||
|
||
const propTypes = { | ||
sizeScale: PropTypes.number, | ||
iconSizeScale: PropTypes.number, | ||
onSelectEmoji: PropTypes.func.isRequired, | ||
}; | ||
|
||
const defaultProps = { | ||
sizeScale: 1, | ||
iconSizeScale: 1, | ||
}; | ||
|
||
const AddReactionBubble = (props) => { | ||
const ref = React.createRef(); | ||
|
||
const onPress = () => { | ||
EmojiPickerAction.showEmojiPicker(() => {}, props.onSelectEmoji, ref.current); | ||
}; | ||
|
||
return ( | ||
<Tooltip text="Add Reaction…"> | ||
<Pressable | ||
ref={ref} | ||
style={({ | ||
hovered, | ||
pressed, | ||
}) => [ | ||
styles.emojiReactionBubble, | ||
StyleUtils.getEmojiReactionBubbleStyle(hovered || pressed, false, props.sizeScale), | ||
]} | ||
onPress={onPress} | ||
> | ||
{({ | ||
hovered, | ||
pressed, | ||
}) => ( | ||
<> | ||
{/* This text will make the view have the same size as a regular | ||
emoji reaction. We make the text invisible and put the | ||
icon on top of it. */} | ||
<Text style={[ | ||
styles.emojiReactionText, | ||
styles.opacity0, | ||
StyleUtils.getEmojiReactionTextStyle(props.sizeScale), | ||
]} | ||
> | ||
aw | ||
</Text> | ||
<View style={styles.pAbsolute}> | ||
<Icon | ||
src={Expensicons.AddReaction} | ||
width={16 * props.iconSizeScale} | ||
height={16 * props.iconSizeScale} | ||
fill={StyleUtils.getIconFillColor( | ||
getButtonState(hovered, pressed), | ||
)} | ||
/> | ||
</View> | ||
</> | ||
)} | ||
</Pressable> | ||
|
||
</Tooltip> | ||
); | ||
}; | ||
|
||
AddReactionBubble.propTypes = propTypes; | ||
AddReactionBubble.defaultProps = defaultProps; | ||
AddReactionBubble.displayName = 'AddReactionBubble'; | ||
|
||
export default AddReactionBubble; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {Pressable} from 'react-native'; | ||
import _ from 'underscore'; | ||
import styles from '../../styles/styles'; | ||
import Text from '../Text'; | ||
import * as StyleUtils from '../../styles/StyleUtils'; | ||
import emojis from '../../../assets/emojis'; | ||
|
||
const propTypes = { | ||
emojiName: PropTypes.string.isRequired, | ||
emojiCodes: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
onPress: PropTypes.func.isRequired, | ||
onLongPress: PropTypes.func, | ||
count: PropTypes.number, | ||
hasUserReacted: PropTypes.bool, | ||
senderIDs: PropTypes.arrayOf(PropTypes.string), | ||
sizeScale: PropTypes.number, | ||
}; | ||
|
||
const defaultProps = { | ||
count: 0, | ||
onLongPress: () => {}, | ||
hasUserReacted: false, | ||
senderIDs: [], | ||
sizeScale: 1, | ||
}; | ||
|
||
const EmojiReactionBubble = (props) => { | ||
const emoji = _.find(emojis, e => `${e.name}` === props.emojiName); | ||
if (!emoji || props.senderIDs === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Pressable | ||
style={({hovered}) => [ | ||
styles.emojiReactionBubble, | ||
StyleUtils.getEmojiReactionBubbleStyle(hovered, props.hasUserReacted, props.sizeScale), | ||
]} | ||
onPress={props.onPress} | ||
onLongPress={props.onLongPress} | ||
> | ||
<Text style={[ | ||
styles.emojiReactionText, | ||
StyleUtils.getEmojiReactionTextStyle(props.sizeScale), | ||
]} | ||
> | ||
{props.emojiCodes.join('')} | ||
</Text> | ||
{props.count > 0 && ( | ||
<Text style={[ | ||
styles.reactionCounterText, | ||
StyleUtils.getEmojiReactionCounterTextStyle(props.hasUserReacted, props.sizeScale), | ||
]} | ||
> | ||
{props.count} | ||
</Text> | ||
)} | ||
</Pressable> | ||
); | ||
}; | ||
|
||
EmojiReactionBubble.propTypes = propTypes; | ||
EmojiReactionBubble.defaultProps = defaultProps; | ||
EmojiReactionBubble.displayName = 'EmojiReactionBubble'; | ||
|
||
export default EmojiReactionBubble; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {View} from 'react-native'; | ||
import _ from 'underscore'; | ||
import EmojiReactionBubble from './EmojiReactionBubble'; | ||
import AddReactionBubble from './AddReactionBubble'; | ||
|
||
const QUICK_REACTIONS = [ | ||
{ | ||
name: '+1', | ||
codes: ['👍'], | ||
}, | ||
{ | ||
name: 'heart', | ||
codes: ['❤️'], | ||
}, | ||
{ | ||
name: 'joy', | ||
codes: ['😂'], | ||
}, | ||
{ | ||
name: 'fire', | ||
codes: ['🔥'], | ||
}, | ||
]; | ||
|
||
const EMOJI_BUBBLE_SCALE = 1.5; | ||
|
||
const QuickEmojiReactions = () => ( | ||
<View style={{ | ||
flexDirection: 'row', | ||
paddingHorizontal: 30, | ||
paddingVertical: 12, | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
{_.map(QUICK_REACTIONS, reaction => ( | ||
<EmojiReactionBubble | ||
key={reaction.name} | ||
onPress={console.log} | ||
emojiName={reaction.name} | ||
emojiCodes={reaction.codes} | ||
sizeScale={EMOJI_BUBBLE_SCALE} | ||
/> | ||
))} | ||
<AddReactionBubble | ||
iconSizeScale={1.2} | ||
onSelectEmoji={console.log} | ||
sizeScale={EMOJI_BUBBLE_SCALE} | ||
/> | ||
</View> | ||
); | ||
|
||
QuickEmojiReactions.displayName = 'QuickEmojiReactions'; | ||
export default QuickEmojiReactions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters