2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import {
|
2020-06-15 14:00:46 +00:00
|
|
|
View, Text, FlatList, StyleSheet
|
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';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from './SafeAreaView';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2020-06-15 14:00:46 +00:00
|
|
|
safeArea: {
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
},
|
2019-05-20 20:43:50 +00:00
|
|
|
titleContainer: {
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingVertical: 10
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
fontSize: 16,
|
2020-11-30 21:47:05 +00:00
|
|
|
...sharedStyles.textSemibold,
|
|
|
|
...sharedStyles.textAlignCenter
|
2019-05-20 20:43:50 +00:00
|
|
|
},
|
|
|
|
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 (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView style={styles.safeArea}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<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-07-27 19:53:33 +00:00
|
|
|
name='close'
|
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}
|
2021-02-19 18:05:47 +00:00
|
|
|
backdropOpacity={themes[theme].backdropOpacity}
|
2019-05-20 20:43:50 +00:00
|
|
|
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);
|