2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
2022-04-15 03:11:36 +00:00
|
|
|
import { StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
import sharedStyles from '../../views/Styles';
|
|
|
|
import { getUnreadStyle } from './getUnreadStyle';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
unreadNumberContainerNormal: {
|
|
|
|
height: 21,
|
|
|
|
paddingVertical: 3,
|
|
|
|
paddingHorizontal: 5,
|
|
|
|
borderRadius: 10.5,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
marginLeft: 10
|
|
|
|
},
|
|
|
|
unreadNumberContainerSmall: {
|
|
|
|
borderRadius: 10.5,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
unreadText: {
|
|
|
|
fontSize: 13,
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
},
|
|
|
|
textSmall: {
|
|
|
|
fontSize: 10
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-04-15 02:51:59 +00:00
|
|
|
export interface IUnreadBadge {
|
2022-01-17 16:10:39 +00:00
|
|
|
unread?: number;
|
|
|
|
userMentions?: number;
|
|
|
|
groupMentions?: number;
|
2022-04-15 03:11:36 +00:00
|
|
|
style?: StyleProp<ViewStyle>;
|
2022-01-17 16:10:39 +00:00
|
|
|
tunread?: [];
|
|
|
|
tunreadUser?: [];
|
|
|
|
tunreadGroup?: [];
|
|
|
|
small?: boolean;
|
2022-06-13 13:24:54 +00:00
|
|
|
hideUnreadStatus?: boolean;
|
|
|
|
hideMentionStatus?: boolean;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const UnreadBadge = React.memo(
|
2022-06-13 13:24:54 +00:00
|
|
|
({
|
|
|
|
unread,
|
|
|
|
userMentions,
|
|
|
|
groupMentions,
|
|
|
|
style,
|
|
|
|
tunread,
|
|
|
|
tunreadUser,
|
|
|
|
tunreadGroup,
|
|
|
|
small,
|
|
|
|
hideMentionStatus,
|
|
|
|
hideUnreadStatus
|
|
|
|
}: IUnreadBadge) => {
|
2022-04-12 16:27:05 +00:00
|
|
|
const { theme } = useTheme();
|
2022-04-15 02:51:59 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if ((!unread || unread <= 0) && !tunread?.length) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-04-12 16:27:05 +00:00
|
|
|
|
2022-06-13 13:24:54 +00:00
|
|
|
if (hideUnreadStatus && hideMentionStatus) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return null when hideUnreadStatus is true and isn't a direct mention
|
|
|
|
if (hideUnreadStatus && !((userMentions && userMentions > 0) || tunreadUser?.length)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const { backgroundColor, color } = getUnreadStyle({
|
|
|
|
theme,
|
|
|
|
unread,
|
|
|
|
userMentions,
|
|
|
|
groupMentions,
|
|
|
|
tunread,
|
|
|
|
tunreadUser,
|
|
|
|
tunreadGroup
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!backgroundColor) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let text: any = unread || tunread?.length;
|
|
|
|
if (small && text >= 100) {
|
|
|
|
text = '+99';
|
|
|
|
}
|
|
|
|
if (!small && text >= 1000) {
|
|
|
|
text = '+999';
|
|
|
|
}
|
|
|
|
text = text.toString();
|
|
|
|
|
|
|
|
let minWidth = 21;
|
|
|
|
if (small) {
|
|
|
|
minWidth = 11 + text.length * 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
small ? styles.unreadNumberContainerSmall : styles.unreadNumberContainerNormal,
|
|
|
|
{ backgroundColor, minWidth },
|
|
|
|
style
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.unreadText, small && styles.textSmall, { color }]} numberOfLines={1}>
|
|
|
|
{text}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-04-12 16:27:05 +00:00
|
|
|
export default UnreadBadge;
|