2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import {
|
2019-10-02 12:18:08 +00:00
|
|
|
View, Text, FlatList, StyleSheet, SafeAreaView
|
2019-05-20 20:43:50 +00:00
|
|
|
} from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
|
|
|
|
import Emoji from './message/Emoji';
|
|
|
|
import I18n from '../i18n';
|
|
|
|
import { CustomIcon } from '../lib/Icons';
|
|
|
|
import sharedStyles from '../views/Styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../constants/colors';
|
|
|
|
import { withTheme } from '../theme';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
titleContainer: {
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingVertical: 10
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
textAlign: 'center',
|
|
|
|
fontSize: 16,
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
},
|
|
|
|
reactCount: {
|
|
|
|
fontSize: 13,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
},
|
|
|
|
peopleReacted: {
|
|
|
|
fontSize: 14,
|
|
|
|
...sharedStyles.textMedium
|
|
|
|
},
|
|
|
|
peopleItemContainer: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'column',
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
emojiContainer: {
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
itemContainer: {
|
|
|
|
height: 50,
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
listContainer: {
|
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
closeButton: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
2019-12-04 16:39:53 +00:00
|
|
|
top: 10
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
const standardEmojiStyle = { fontSize: 20 };
|
|
|
|
const customEmojiStyle = { width: 20, height: 20 };
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const Item = React.memo(({
|
2019-12-04 16:39:53 +00:00
|
|
|
item, user, baseUrl, getCustomEmoji, theme
|
2019-09-16 20:26:32 +00:00
|
|
|
}) => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const count = item.usernames.length;
|
|
|
|
let usernames = item.usernames.slice(0, 3)
|
|
|
|
.map(username => (username === user.username ? I18n.t('you') : username)).join(', ');
|
|
|
|
if (count > 3) {
|
|
|
|
usernames = `${ usernames } ${ I18n.t('and_more') } ${ count - 3 }`;
|
|
|
|
} else {
|
|
|
|
usernames = usernames.replace(/,(?=[^,]*$)/, ` ${ I18n.t('and') }`);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.itemContainer}>
|
|
|
|
<View style={styles.emojiContainer}>
|
|
|
|
<Emoji
|
|
|
|
content={item.emoji}
|
|
|
|
standardEmojiStyle={standardEmojiStyle}
|
|
|
|
customEmojiStyle={customEmojiStyle}
|
|
|
|
baseUrl={baseUrl}
|
2019-05-22 14:55:04 +00:00
|
|
|
getCustomEmoji={getCustomEmoji}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.peopleItemContainer}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.reactCount, { color: themes[theme].buttonText }]}>
|
2019-05-20 20:43:50 +00:00
|
|
|
{count === 1 ? I18n.t('1_person_reacted') : I18n.t('N_people_reacted', { n: count })}
|
|
|
|
</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.peopleReacted, { color: themes[theme].buttonText }]}>{ usernames }</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const ModalContent = React.memo(({
|
|
|
|
message, onClose, ...props
|
|
|
|
}) => {
|
2019-05-20 20:43:50 +00:00
|
|
|
if (message && message.reactions) {
|
|
|
|
return (
|
|
|
|
<SafeAreaView style={{ flex: 1 }}>
|
|
|
|
<Touchable onPress={onClose}>
|
|
|
|
<View style={styles.titleContainer}>
|
|
|
|
<CustomIcon
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.closeButton, { color: themes[props.theme].buttonText }]}
|
2020-06-05 13:28:58 +00:00
|
|
|
name='Cross'
|
2019-05-20 20:43:50 +00:00
|
|
|
size={20}
|
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.title, { color: themes[props.theme].buttonText }]}>{I18n.t('Reactions')}</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
</Touchable>
|
|
|
|
<FlatList
|
|
|
|
style={styles.listContainer}
|
|
|
|
data={message.reactions}
|
|
|
|
renderItem={({ item }) => <Item item={item} {...props} />}
|
|
|
|
keyExtractor={item => item.emoji}
|
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const ReactionsModal = React.memo(({
|
|
|
|
isVisible, onClose, theme, ...props
|
|
|
|
}) => (
|
2019-05-20 20:43:50 +00:00
|
|
|
<Modal
|
|
|
|
isVisible={isVisible}
|
|
|
|
onBackdropPress={onClose}
|
|
|
|
onBackButtonPress={onClose}
|
|
|
|
backdropOpacity={0.8}
|
|
|
|
onSwipeComplete={onClose}
|
|
|
|
swipeDirection={['up', 'left', 'right', 'down']}
|
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
<ModalContent onClose={onClose} theme={theme} {...props} />
|
2019-05-20 20:43:50 +00:00
|
|
|
</Modal>
|
2019-12-04 16:39:53 +00:00
|
|
|
), (prevProps, nextProps) => prevProps.isVisible === nextProps.isVisible && prevProps.theme === nextProps.theme);
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
ReactionsModal.propTypes = {
|
|
|
|
isVisible: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
onClose: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
ReactionsModal.displayName = 'ReactionsModal';
|
|
|
|
|
|
|
|
ModalContent.propTypes = {
|
|
|
|
message: PropTypes.object,
|
2019-12-04 16:39:53 +00:00
|
|
|
onClose: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
ModalContent.displayName = 'ReactionsModalContent';
|
|
|
|
|
|
|
|
Item.propTypes = {
|
|
|
|
item: PropTypes.object,
|
|
|
|
user: PropTypes.object,
|
2019-09-16 20:26:32 +00:00
|
|
|
baseUrl: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
getCustomEmoji: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Item.displayName = 'ReactionsModalItem';
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default withTheme(ReactionsModal);
|