-
Notifications
You must be signed in to change notification settings - Fork 305
/
ChannelPreviewUnreadCount.tsx
59 lines (51 loc) · 1.66 KB
/
ChannelPreviewUnreadCount.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { ChannelPreviewProps } from './ChannelPreview';
import type { ChannelsContextValue } from '../../contexts/channelsContext/ChannelsContext';
import { useTheme } from '../../contexts/themeContext/ThemeContext';
import type { DefaultStreamChatGenerics } from '../../types/types';
export type ChannelPreviewUnreadCountProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Pick<ChannelsContextValue<StreamChatGenerics>, 'maxUnreadCount'> &
Pick<ChannelPreviewProps<StreamChatGenerics>, 'channel'> & {
/**
* Number of unread messages on the channel
*/
unread?: number;
};
export const ChannelPreviewUnreadCount = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
props: ChannelPreviewUnreadCountProps<StreamChatGenerics>,
) => {
const { maxUnreadCount, unread } = props;
const {
theme: {
channelPreview: { unreadContainer, unreadText },
colors: { accent_red },
},
} = useTheme();
if (!unread) return null;
return (
<View style={[styles.unreadContainer, { backgroundColor: accent_red }, unreadContainer]}>
<Text numberOfLines={1} style={[styles.unreadText, unreadText]}>
{unread > maxUnreadCount ? `${maxUnreadCount}+` : unread}
</Text>
</View>
);
};
const styles = StyleSheet.create({
unreadContainer: {
alignItems: 'center',
borderRadius: 8,
flexShrink: 1,
justifyContent: 'center',
},
unreadText: {
color: '#FFFFFF',
fontSize: 11,
fontWeight: '700',
paddingHorizontal: 5,
paddingVertical: 1,
},
});