Skip to content

Commit

Permalink
unread: Move a UI-specific helper to the appropriate bit of UI.
Browse files Browse the repository at this point in the history
This is basically part of the UI logic; it's a choice for how to
represent this information visually.  Move it to the relevant spot
of our UI code.

Then as a bonus, inline it and use that to simplify the logic.
  • Loading branch information
gnprice committed Jul 17, 2019
1 parent dd31d12 commit 139b7d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/common/UnreadCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { StyleSheet, Text, View } from 'react-native';
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';

import { BRAND_COLOR } from '../styles';
import { unreadToLimitedCount } from '../utils/unread';
import { foregroundColorFromBackground } from '../utils/color';

const styles = StyleSheet.create({
Expand Down Expand Up @@ -83,10 +82,11 @@ export default class UnreadCount extends PureComponent<Props> {
const textColor = foregroundColorFromBackground(color);
const textStyle = [styles.text, inverse && styles.textInverse, { color: textColor }];

const countString = limited && count >= 100 ? '99+' : count.toString();
return (
<View style={frameStyle}>
<Text style={textStyle} numberOfLines={1}>
{limited ? unreadToLimitedCount(count) : count}
{countString}
</Text>
</View>
);
Expand Down
3 changes: 0 additions & 3 deletions src/utils/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ export const filterUnreadMessagesInRange = (
.filter(msg => msg.id >= fromId && msg.id <= toId);
return filterUnreadMessageIds(messagesInRange.map(x => x.id), flags);
};

export const unreadToLimitedCount = (count: number): string =>
count < 100 ? count.toString() : '99+';

0 comments on commit 139b7d1

Please sign in to comment.