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

94 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';
import sharedStyles from '../../views/Styles';
import { getUnreadStyle } from './getUnreadStyle';
import { withTheme } from '../../theme';
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,
[NEW] Threads (#2567) * [IMPROVEMENT] Mentions layout without background * Fix RoomItem * Fix tests * Smaller messagebox * Messagebox colors tweak * Beginning header buttons refactor * Add HeaderButtons * item with title * Refactor * Remove lib * Refactor * Update snapshot * Send to channel on messagebox * Add tshow * Add showMessageInMainThread to login.user reducer * Filter threads on main channel based on user setting * Send tshow * Add tunread * Move unread colors logic away from UnreadBadge component so it can be used on other components * Export UnreadBadge on index * Add empty test * Refactor * Update tests * Lint * Thread unread user and group on RoomItem * Thread badge working * Started ThreadMessagesView.Item * Fix separator * Reactivity working * Lint * custom emojis aren't necessary * Basic filter layout * Filtering layout * Refactor * apply filter * DropdownItemHeader * default all * few fixes * No data found * Fixes list performance issues * Use locale on date formats * Fixed minor styles * Thread badge * Refactor getBadgeColor * Fix send to channel background color * starting search threads * Fix lint and tests * Bump to 4.12.0 just for testing :) * Search input layout * query * starting threads header * fix unnecessary tlm on tmid messages * Fix thread header * lint * Fix thread header on ShareView * Add e2e tests * Fix subscriptions sort * Update stories and minor fixes * Fix button sizes on Messagebox * Remove comment * Unnecessary conditional * Add showMessageInMainThread to user collection * Fix thread header * Fix thread messages not working on tablet * Reset Messagebox.tshow after sending a message * Allow to send to channel when replying to a thread from main channel * Unnecessary theme prop * Address comments * Remove re-render * Fix scroll indicator bug * Fix style * Minor i18n fix * Fix dropdown height * I18n ptbr * I18n
2020-10-30 17:35:07 +00:00
...sharedStyles.textSemibold
},
textSmall: {
fontSize: 10
}
});
const UnreadBadge = React.memo(({
theme, unread, userMentions, groupMentions, style, tunread, tunreadUser, tunreadGroup, small
}) => {
if ((!unread || unread <= 0) && (!tunread?.length)) {
return null;
}
const { backgroundColor, color } = getUnreadStyle({
theme, unread, userMentions, groupMentions, tunread, tunreadUser, tunreadGroup
});
if (!backgroundColor) {
return null;
}
let text = 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
]}
>
<Text
style={[
styles.unreadText,
small && styles.textSmall,
{ color }
]}
numberOfLines={1}
>{text}
</Text>
</View>
);
});
UnreadBadge.propTypes = {
theme: PropTypes.string,
unread: PropTypes.number,
userMentions: PropTypes.number,
groupMentions: PropTypes.number,
style: PropTypes.object,
tunread: PropTypes.array,
tunreadUser: PropTypes.array,
tunreadGroup: PropTypes.array,
small: PropTypes.bool
};
export default withTheme(UnreadBadge);