2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View, Text } from 'react-native';
|
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import styles from './styles';
|
|
|
|
import Emoji from './Emoji';
|
|
|
|
import { BUTTON_HIT_SLOP } from './utils';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
const AddReaction = React.memo(({ reactionInit, theme }) => (
|
2019-05-20 20:43:50 +00:00
|
|
|
<Touchable
|
2019-10-07 20:56:30 +00:00
|
|
|
onPress={reactionInit}
|
2019-05-20 20:43:50 +00:00
|
|
|
key='message-add-reaction'
|
|
|
|
testID='message-add-reaction'
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.reactionButton, { backgroundColor: themes[theme].backgroundColor }]}
|
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
2019-05-20 20:43:50 +00:00
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
>
|
2019-12-11 23:01:12 +00:00
|
|
|
<View style={[styles.reactionContainer, { borderColor: themes[theme].borderColor }]}>
|
|
|
|
<CustomIcon name='add-reaction' size={21} color={themes[theme].tintColor} />
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
</Touchable>
|
|
|
|
));
|
|
|
|
|
|
|
|
const Reaction = React.memo(({
|
2019-12-11 23:01:12 +00:00
|
|
|
reaction, user, onReactionLongPress, onReactionPress, baseUrl, getCustomEmoji, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
|
|
|
const reacted = reaction.usernames.findIndex(item => item === user.username) !== -1;
|
|
|
|
return (
|
|
|
|
<Touchable
|
|
|
|
onPress={() => onReactionPress(reaction.emoji)}
|
|
|
|
onLongPress={onReactionLongPress}
|
|
|
|
key={reaction.emoji}
|
|
|
|
testID={`message-reaction-${ reaction.emoji }`}
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.reactionButton, { backgroundColor: reacted ? themes[theme].bannerBackground : themes[theme].backgroundColor }]}
|
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
2019-05-20 20:43:50 +00:00
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
>
|
2019-12-11 23:01:12 +00:00
|
|
|
<View style={[styles.reactionContainer, { borderColor: reacted ? themes[theme].tintColor : themes[theme].borderColor }]}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<Emoji
|
|
|
|
content={reaction.emoji}
|
|
|
|
standardEmojiStyle={styles.reactionEmoji}
|
|
|
|
customEmojiStyle={styles.reactionCustomEmoji}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
getCustomEmoji={getCustomEmoji}
|
|
|
|
/>
|
2019-12-11 23:01:12 +00:00
|
|
|
<Text style={[styles.reactionCount, { color: themes[theme].tintColor }]}>{ reaction.usernames.length }</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
</Touchable>
|
|
|
|
);
|
2019-05-23 17:51:42 +00:00
|
|
|
});
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const Reactions = React.memo(({
|
2019-12-11 23:01:12 +00:00
|
|
|
reactions, user, baseUrl, onReactionPress, reactionInit, onReactionLongPress, getCustomEmoji, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2020-02-19 19:43:47 +00:00
|
|
|
if (!Array.isArray(reactions) || reactions.length === 0) {
|
2019-05-20 20:43:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.reactionsContainer}>
|
|
|
|
{reactions.map(reaction => (
|
|
|
|
<Reaction
|
|
|
|
key={reaction.emoji}
|
|
|
|
reaction={reaction}
|
|
|
|
user={user}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
onReactionLongPress={onReactionLongPress}
|
|
|
|
onReactionPress={onReactionPress}
|
|
|
|
getCustomEmoji={getCustomEmoji}
|
2019-12-11 23:01:12 +00:00
|
|
|
theme={theme}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
))}
|
2019-12-11 23:01:12 +00:00
|
|
|
<AddReaction reactionInit={reactionInit} theme={theme} />
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Reaction.propTypes = {
|
|
|
|
reaction: PropTypes.object,
|
|
|
|
user: PropTypes.object,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
onReactionPress: PropTypes.func,
|
|
|
|
onReactionLongPress: PropTypes.func,
|
2019-12-11 23:01:12 +00:00
|
|
|
getCustomEmoji: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Reaction.displayName = 'MessageReaction';
|
|
|
|
|
|
|
|
Reactions.propTypes = {
|
|
|
|
reactions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
|
|
user: PropTypes.object,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
onReactionPress: PropTypes.func,
|
2019-10-07 20:56:30 +00:00
|
|
|
reactionInit: PropTypes.func,
|
2019-05-20 20:43:50 +00:00
|
|
|
onReactionLongPress: PropTypes.func,
|
2019-12-11 23:01:12 +00:00
|
|
|
getCustomEmoji: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Reactions.displayName = 'MessageReactions';
|
|
|
|
|
|
|
|
AddReaction.propTypes = {
|
2019-12-11 23:01:12 +00:00
|
|
|
reactionInit: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
AddReaction.displayName = 'MessageAddReaction';
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
export default withTheme(Reactions);
|