Rocket.Chat.ReactNative/app/presentation/RoomItem/UnreadBadge.js

52 lines
1013 B
JavaScript
Raw Normal View History

2019-04-18 20:57:35 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { View, Text } from 'react-native';
import styles from './styles';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
2019-04-18 20:57:35 +00:00
2019-12-04 16:39:53 +00:00
const UnreadBadge = React.memo(({
theme, unread, userMentions, groupMentions
2019-12-04 16:39:53 +00:00
}) => {
2019-04-18 20:57:35 +00:00
if (!unread || unread <= 0) {
return;
}
if (unread >= 1000) {
unread = '999+';
}
let backgroundColor = themes[theme].unreadBackground;
const color = themes[theme].buttonText;
if (userMentions > 0) {
backgroundColor = themes[theme].mentionMeColor;
} else if (groupMentions > 0) {
backgroundColor = themes[theme].mentionGroupColor;
}
2019-04-18 20:57:35 +00:00
return (
2019-12-04 16:39:53 +00:00
<View
style={[
styles.unreadNumberContainer,
{ backgroundColor }
2019-12-04 16:39:53 +00:00
]}
>
<Text
style={[
styles.unreadText,
{ color }
2019-12-04 16:39:53 +00:00
]}
>{ unread }
</Text>
2019-04-18 20:57:35 +00:00
</View>
);
});
UnreadBadge.propTypes = {
2019-12-04 16:39:53 +00:00
theme: PropTypes.string,
2019-04-18 20:57:35 +00:00
unread: PropTypes.number,
userMentions: PropTypes.number,
groupMentions: PropTypes.number
2019-04-18 20:57:35 +00:00
};
export default UnreadBadge;