Skip to content

Commit c9d9211

Browse files
authored
feat: add muted channel status in Channel list screen (#1087)
docs: add channel muted status props documentation and name fixes fix: markdown lint issues fix: theming of the ChannelPreviewMutedStatus component
1 parent 4fd91ec commit c9d9211

File tree

8 files changed

+140
-2
lines changed

8 files changed

+140
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Channel muted status component rendered within [`Preview`](../../../../ui-components/channel_preview_muted_status.mdx).
2+
3+
| Type | Default |
4+
| --------- | --------------------------------------------------------------------------------------- |
5+
| component | [ChannelPreviewMutedStatus](../../../../ui-components/channel_preview_muted_status.mdx) |

docusaurus/docs/reactnative/core-components/channel_list.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import LoadingIndicator from '../common-content/core-components/channel-list/pro
3737
import Preview from '../common-content/core-components/channel-list/props/preview.mdx';
3838
import PreviewAvatar from '../common-content/core-components/channel-list/props/preview_avatar.mdx';
3939
import PreviewMessage from '../common-content/core-components/channel-list/props/preview_message.mdx';
40+
import PreviewMutedStatus from '../common-content/core-components/channel-list/props/preview_muted_status.mdx';
4041
import PreviewStatus from '../common-content/core-components/channel-list/props/preview_status.mdx';
4142
import PreviewTitle from '../common-content/core-components/channel-list/props/preview_title.mdx';
4243
import PreviewUnreadCount from '../common-content/core-components/channel-list/props/preview_unread_count.mdx';
@@ -236,6 +237,10 @@ const CustomPreviewTitle = ({ channel }) => (
236237

237238
<PreviewMessage />
238239

240+
### PreviewMutedStatus
241+
242+
<PreviewMutedStatus />
243+
239244
### PreviewStatus
240245

241246
<PreviewStatus />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
id: channel-preview-muted_status
3+
title: ChannelPreviewMutedStatus
4+
---
5+
6+
import Channel from '../common-content/ui-components/channel-preview-messenger/props/channel.mdx';
7+
8+
Component to render the muted status for a channel, within the [`ChannelList`](../core-components/channel_list.mdx) component.
9+
This is the default component provided to the prop [`PreviewMutedStatus`](../core-components/channel_list.mdx#previewmutedstatus) on the `ChannelList` component.
10+
11+
## Props
12+
13+
### <div class="label required">required</div> **channel**
14+
15+
<Channel />
16+
17+
### <div class="label required">required</div> **muted**
18+
19+
Value which stores the muted status of the Channel
20+
21+
| Type |
22+
| ------- |
23+
| boolean |

docusaurus/docs/reactnative/ui-components/channel_preview_title.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ Formatted name for the previewed channel.
1818
| ------ |
1919
| string |
2020

21-
### channel
21+
### <div class="label required">required</div> **channel**
2222

2323
<Channel />

package/src/components/ChannelPreview/ChannelPreviewMessenger.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TouchableOpacity } from 'react-native-gesture-handler';
55
import { ChannelAvatar } from './ChannelAvatar';
66
import type { ChannelPreviewProps } from './ChannelPreview';
77
import { ChannelPreviewMessage } from './ChannelPreviewMessage';
8+
import { ChannelPreviewMutedStatus } from './ChannelPreviewMutedStatus';
89
import { ChannelPreviewStatus } from './ChannelPreviewStatus';
910
import { ChannelPreviewTitle } from './ChannelPreviewTitle';
1011
import { ChannelPreviewUnreadCount } from './ChannelPreviewUnreadCount';
@@ -45,6 +46,10 @@ const styles = StyleSheet.create({
4546
justifyContent: 'space-between',
4647
paddingLeft: 8,
4748
},
49+
statusContainer: {
50+
display: 'flex',
51+
flexDirection: 'row',
52+
},
4853
title: { fontSize: 14, fontWeight: '700' },
4954
});
5055

@@ -65,6 +70,7 @@ export type ChannelPreviewMessengerPropsWithContext<
6570
| 'onSelect'
6671
| 'PreviewAvatar'
6772
| 'PreviewMessage'
73+
| 'PreviewMutedStatus'
6874
| 'PreviewStatus'
6975
| 'PreviewTitle'
7076
| 'PreviewUnreadCount'
@@ -125,6 +131,7 @@ const ChannelPreviewMessengerWithContext = <
125131
PreviewStatus = ChannelPreviewStatus,
126132
PreviewTitle = ChannelPreviewTitle,
127133
PreviewUnreadCount = ChannelPreviewUnreadCount,
134+
PreviewMutedStatus = ChannelPreviewMutedStatus,
128135
unread,
129136
} = props;
130137

@@ -140,6 +147,8 @@ const ChannelPreviewMessengerWithContext = <
140147
Math.floor(maxWidth / ((title.fontSize || styles.title.fontSize) / 2)),
141148
);
142149

150+
const isChannelMuted = channel.muteStatus().muted;
151+
143152
return (
144153
<TouchableOpacity
145154
onPress={() => {
@@ -161,7 +170,10 @@ const ChannelPreviewMessengerWithContext = <
161170
>
162171
<View style={[styles.row, row]}>
163172
<PreviewTitle channel={channel} displayName={displayName} />
164-
<PreviewUnreadCount channel={channel} maxUnreadCount={maxUnreadCount} unread={unread} />
173+
<View style={[styles.statusContainer, row]}>
174+
<PreviewMutedStatus channel={channel} muted={isChannelMuted} />
175+
<PreviewUnreadCount channel={channel} maxUnreadCount={maxUnreadCount} unread={unread} />
176+
</View>
165177
</View>
166178
<View style={[styles.row, row]}>
167179
<PreviewMessage latestMessagePreview={latestMessagePreview} />
@@ -219,6 +231,7 @@ export const ChannelPreviewMessenger = <
219231
onSelect,
220232
PreviewAvatar,
221233
PreviewMessage,
234+
PreviewMutedStatus,
222235
PreviewStatus,
223236
PreviewTitle,
224237
PreviewUnreadCount,
@@ -230,6 +243,7 @@ export const ChannelPreviewMessenger = <
230243
onSelect,
231244
PreviewAvatar,
232245
PreviewMessage,
246+
PreviewMutedStatus,
233247
PreviewStatus,
234248
PreviewTitle,
235249
PreviewUnreadCount,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React from 'react';
2+
3+
import { StyleSheet } from 'react-native';
4+
5+
import type { ChannelPreviewProps } from './ChannelPreview';
6+
7+
import { useTheme } from '../../contexts/themeContext/ThemeContext';
8+
import { Mute } from '../../icons';
9+
import type {
10+
DefaultAttachmentType,
11+
DefaultChannelType,
12+
DefaultCommandType,
13+
DefaultEventType,
14+
DefaultMessageType,
15+
DefaultReactionType,
16+
DefaultUserType,
17+
UnknownType,
18+
} from '../../types/types';
19+
20+
const styles = StyleSheet.create({
21+
iconStyle: {
22+
marginRight: 8,
23+
},
24+
});
25+
26+
export type ChannelPreviewMutedStatusProps<
27+
At extends UnknownType = DefaultAttachmentType,
28+
Ch extends UnknownType = DefaultChannelType,
29+
Co extends string = DefaultCommandType,
30+
Ev extends UnknownType = DefaultEventType,
31+
Me extends UnknownType = DefaultMessageType,
32+
Re extends UnknownType = DefaultReactionType,
33+
Us extends UnknownType = DefaultUserType,
34+
> = Pick<ChannelPreviewProps<At, Ch, Co, Ev, Me, Re, Us>, 'channel'> & {
35+
muted: boolean;
36+
};
37+
38+
/**
39+
* This UI component displays an avatar for a particular channel.
40+
*/
41+
export const ChannelPreviewMutedStatus = <
42+
At extends UnknownType = DefaultAttachmentType,
43+
Ch extends UnknownType = DefaultChannelType,
44+
Co extends string = DefaultCommandType,
45+
Ev extends UnknownType = DefaultEventType,
46+
Me extends UnknownType = DefaultMessageType,
47+
Re extends UnknownType = DefaultReactionType,
48+
Us extends UnknownType = DefaultUserType,
49+
>(
50+
props: ChannelPreviewMutedStatusProps<At, Ch, Co, Ev, Me, Re, Us>,
51+
) => {
52+
const { muted } = props;
53+
54+
const {
55+
theme: {
56+
channelPreview: {
57+
mutedStatus: { height, iconStyle, width },
58+
},
59+
colors: { grey_dark },
60+
},
61+
} = useTheme();
62+
63+
return muted ? (
64+
<Mute
65+
height={height}
66+
pathFill={grey_dark}
67+
style={[styles.iconStyle, iconStyle]}
68+
width={width}
69+
/>
70+
) : null;
71+
};

package/src/contexts/channelsContext/ChannelsContext.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import React, { PropsWithChildren, useContext } from 'react';
33
import type { FlatListProps } from 'react-native';
44
import type { FlatList } from 'react-native-gesture-handler';
55

6+
import type { ChannelPreviewMutedStatusProps } from 'src/components/ChannelPreview/ChannelPreviewMutedStatus';
7+
68
import type { Channel } from 'stream-chat';
79

810
import type { HeaderErrorProps } from '../../components/ChannelList/ChannelListHeaderErrorIndicator';
@@ -194,6 +196,14 @@ export type ChannelsContextValue<
194196
* **Default** [ChannelPreviewMessage](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/ChannelPreview/ChannelPreviewMessage.tsx)
195197
*/
196198
PreviewMessage?: React.ComponentType<ChannelPreviewMessageProps<At, Ch, Co, Ev, Me, Re, Us>>;
199+
/**
200+
* Custom UI component to render muted status.
201+
*
202+
* **Default** [ChannelMutedStatus](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/ChannelPreview/ChannelPreviewMutedStatus.tsx)
203+
*/
204+
PreviewMutedStatus?: React.ComponentType<
205+
ChannelPreviewMutedStatusProps<At, Ch, Co, Ev, Me, Re, Us>
206+
>;
197207
/**
198208
* Custom UI component to render preview avatar.
199209
*

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ export type Theme = {
134134
message: TextStyle & {
135135
fontWeight: TextStyle['fontWeight'];
136136
};
137+
mutedStatus: {
138+
height: number;
139+
iconStyle: ViewStyle;
140+
width: number;
141+
};
137142
row: ViewStyle;
138143
title: TextStyle;
139144
unreadContainer: ViewStyle;
@@ -587,6 +592,11 @@ export const defaultTheme: Theme = {
587592
message: {
588593
fontWeight: '400',
589594
},
595+
mutedStatus: {
596+
height: 20,
597+
iconStyle: {},
598+
width: 20,
599+
},
590600
row: {},
591601
title: {},
592602
unreadContainer: {},

0 commit comments

Comments
 (0)