2019-04-18 20:57:35 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-07-31 18:22:30 +00:00
|
|
|
import { View, Text, StyleSheet } from 'react-native';
|
2019-04-18 20:57:35 +00:00
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
import sharedStyles from '../views/Styles';
|
|
|
|
import { themes } from '../constants/colors';
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
unreadNumberContainer: {
|
|
|
|
minWidth: 21,
|
|
|
|
height: 21,
|
|
|
|
paddingVertical: 3,
|
|
|
|
paddingHorizontal: 5,
|
|
|
|
borderRadius: 10.5,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
marginLeft: 10
|
|
|
|
},
|
|
|
|
unreadText: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
fontSize: 13,
|
|
|
|
...sharedStyles.textMedium,
|
|
|
|
letterSpacing: 0.56,
|
|
|
|
textAlign: 'center'
|
|
|
|
}
|
|
|
|
});
|
2019-04-18 20:57:35 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const UnreadBadge = React.memo(({
|
2020-07-31 18:22:30 +00:00
|
|
|
theme, unread, userMentions, groupMentions, style
|
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+';
|
|
|
|
}
|
2020-07-29 20:49:08 +00:00
|
|
|
|
|
|
|
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,
|
2020-07-31 18:22:30 +00:00
|
|
|
{ backgroundColor },
|
|
|
|
style
|
2019-12-04 16:39:53 +00:00
|
|
|
]}
|
|
|
|
>
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.unreadText,
|
2020-07-29 20:49:08 +00:00
|
|
|
{ color }
|
2019-12-04 16:39:53 +00:00
|
|
|
]}
|
2020-07-31 18:22:30 +00:00
|
|
|
>{unread}
|
2019-12-04 16:39:53 +00:00
|
|
|
</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,
|
2020-07-31 18:22:30 +00:00
|
|
|
groupMentions: PropTypes.number,
|
|
|
|
style: PropTypes.object
|
2019-04-18 20:57:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default UnreadBadge;
|