verdnatura-chat/app/presentation/UnreadBadge.js

74 lines
1.4 KiB
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, StyleSheet } from 'react-native';
2019-04-18 20:57:35 +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(({
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+';
}
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 },
style
2019-12-04 16:39:53 +00:00
]}
>
<Text
style={[
styles.unreadText,
{ color }
2019-12-04 16:39:53 +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,
groupMentions: PropTypes.number,
style: PropTypes.object
2019-04-18 20:57:35 +00:00
};
export default UnreadBadge;