2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
2021-07-27 19:33:38 +00:00
|
|
|
import { View, Text, FlatList, StyleSheet } 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-07-27 15:27:17 +00:00
|
|
|
type TItem = {
|
|
|
|
item: {
|
|
|
|
usernames: any;
|
|
|
|
emoji: string;
|
|
|
|
};
|
|
|
|
user?: {username: any;};
|
|
|
|
baseUrl?: string;
|
|
|
|
getCustomEmoji?: Function;
|
|
|
|
theme?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type TModalContent = {
|
|
|
|
message: {
|
|
|
|
reactions: any
|
|
|
|
};
|
|
|
|
onClose: Function;
|
|
|
|
theme: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IReactionsModal {
|
|
|
|
isVisible: boolean;
|
|
|
|
onClose(): void;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Item = React.memo(({ item, user, baseUrl, getCustomEmoji, theme }: TItem) => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const count = item.usernames.length;
|
|
|
|
let usernames = item.usernames.slice(0, 3)
|
2021-07-27 15:27:17 +00:00
|
|
|
.map((username: any) => (username === user?.username ? I18n.t('you') : username)).join(', ');
|
2019-05-20 20:43:50 +00:00
|
|
|
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}
|
2021-07-27 15:27:17 +00:00
|
|
|
baseUrl={baseUrl!}
|
|
|
|
getCustomEmoji={getCustomEmoji!}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.peopleItemContainer}>
|
2021-07-27 15:27:17 +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-07-27 15:27:17 +00:00
|
|
|
<Text style={[styles.peopleReacted, { color: themes[theme!].buttonText }]}>{ usernames }</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-27 15:27:17 +00:00
|
|
|
const ModalContent = React.memo(({ message, onClose, ...props }: TModalContent) => {
|
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;
|
|
|
|
});
|
|
|
|
|
2021-07-27 15:27:17 +00:00
|
|
|
const ReactionsModal = React.memo(({ isVisible, onClose, theme, ...props }: IReactionsModal) => (
|
2019-05-20 20:43:50 +00:00
|
|
|
<Modal
|
|
|
|
isVisible={isVisible}
|
|
|
|
onBackdropPress={onClose}
|
|
|
|
onBackButtonPress={onClose}
|
2021-02-26 18:44:00 +00:00
|
|
|
backdropOpacity={0.8}
|
2019-05-20 20:43:50 +00:00
|
|
|
onSwipeComplete={onClose}
|
|
|
|
swipeDirection={['up', 'left', 'right', 'down']}
|
|
|
|
>
|
2021-07-27 15:27:17 +00:00
|
|
|
{/*@ts-ignore*/}
|
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.displayName = 'ReactionsModal';
|
|
|
|
ModalContent.displayName = 'ReactionsModalContent';
|
|
|
|
Item.displayName = 'ReactionsModalItem';
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default withTheme(ReactionsModal);
|