2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { FlatList, StyleSheet, Text, View } from 'react-native';
|
2019-05-20 20:43:50 +00:00
|
|
|
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 };
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
interface IItem {
|
|
|
|
item: {
|
|
|
|
usernames: any;
|
|
|
|
emoji: string;
|
|
|
|
};
|
|
|
|
user?: { username: any };
|
|
|
|
baseUrl?: string;
|
|
|
|
getCustomEmoji?: Function;
|
|
|
|
theme?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IModalContent {
|
|
|
|
message?: {
|
|
|
|
reactions: any;
|
|
|
|
};
|
|
|
|
onClose: Function;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IReactionsModal {
|
|
|
|
isVisible: boolean;
|
|
|
|
onClose(): void;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Item = React.memo(({ item, user, baseUrl, getCustomEmoji, theme }: IItem) => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const count = item.usernames.length;
|
2021-10-01 18:12:19 +00:00
|
|
|
let usernames = item.usernames
|
|
|
|
.slice(0, 3)
|
|
|
|
.map((username: any) => (username === user?.username ? I18n.t('you') : username))
|
|
|
|
.join(', ');
|
2019-05-20 20:43:50 +00:00
|
|
|
if (count > 3) {
|
2021-10-01 18:12:19 +00:00
|
|
|
usernames = `${usernames} ${I18n.t('and_more')} ${count - 3}`;
|
2019-05-20 20:43:50 +00:00
|
|
|
} else {
|
2021-10-01 18:12:19 +00:00
|
|
|
usernames = usernames.replace(/,(?=[^,]*$)/, ` ${I18n.t('and')}`);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.itemContainer}>
|
|
|
|
<View style={styles.emojiContainer}>
|
|
|
|
<Emoji
|
|
|
|
content={item.emoji}
|
|
|
|
standardEmojiStyle={standardEmojiStyle}
|
|
|
|
customEmojiStyle={customEmojiStyle}
|
2021-10-01 18:12:19 +00:00
|
|
|
baseUrl={baseUrl!}
|
|
|
|
getCustomEmoji={getCustomEmoji!}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.peopleItemContainer}>
|
2021-10-01 18:12:19 +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>
|
2021-10-01 18:12:19 +00:00
|
|
|
<Text style={[styles.peopleReacted, { color: themes[theme!].buttonText }]}>{usernames}</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const ModalContent = React.memo(({ message, onClose, ...props }: IModalContent) => {
|
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}>
|
2021-10-01 18:12:19 +00:00
|
|
|
<CustomIcon style={[styles.closeButton, { color: themes[props.theme].buttonText }]} name='close' 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;
|
|
|
|
});
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const ReactionsModal = React.memo(
|
|
|
|
({ isVisible, onClose, theme, ...props }: IReactionsModal) => (
|
|
|
|
<Modal
|
|
|
|
isVisible={isVisible}
|
|
|
|
onBackdropPress={onClose}
|
|
|
|
onBackButtonPress={onClose}
|
|
|
|
backdropOpacity={0.8}
|
|
|
|
onSwipeComplete={onClose}
|
|
|
|
swipeDirection={['up', 'left', 'right', 'down']}>
|
|
|
|
<ModalContent onClose={onClose} theme={theme} {...props} />
|
|
|
|
</Modal>
|
|
|
|
),
|
|
|
|
(prevProps, nextProps) => prevProps.isVisible === nextProps.isVisible && prevProps.theme === nextProps.theme
|
|
|
|
);
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
ReactionsModal.displayName = 'ReactionsModal';
|
|
|
|
ModalContent.displayName = 'ReactionsModalContent';
|
|
|
|
Item.displayName = 'ReactionsModalItem';
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default withTheme(ReactionsModal);
|