Skip to content

Commit 2033017

Browse files
authored
Merge pull request #1456 from GetStream/develop
2 parents fa20099 + 46ffef9 commit 2033017

File tree

194 files changed

+8866
-14433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+8866
-14433
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Feature request
3+
about: Describe a new feature
4+
title: ''
5+
labels: feature
6+
assignees: ''
7+
8+
---
9+
10+
**Motivation**
11+
A clear and concise description of what the problem/opportunity is. Ex. I'm always frustrated when [...]
12+
13+
**Proposed solution**
14+
A clear and concise description of what you want to happen.
15+
16+
**Acceptance Criteria**
17+
A set of predefined requirements that must be met to mark a user story complete.
357 KB
Loading
171 KB
Loading

docusaurus/docs/React/contexts/channel-state-context.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ Error object (if any) in loading the `channel`, otherwise null.
6565
| ------ |
6666
| object |
6767

68+
### giphyVersion
69+
70+
The giphy version to use when displaying giphies.
71+
72+
| Type |
73+
| --------------------------------------------------------------------------------------------------------------------------------------------------- |
74+
| `'original' | 'fixed_height' | 'fixed_height_still' | 'fixed_height_downsampled' | 'fixed_width' | 'fixed_width_still' | 'fixed_width_downsampled'` |
75+
6876
### hasMore
6977

7078
If the channel has more messages to paginate through.

docusaurus/docs/React/core-components/channel.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ Custom UI component to render a Giphy preview in the `VirtualizedMessageList`.
262262
| --------- | ------------------------------------------------------------------------------------------------------------------------------------ |
263263
| component | [GiphyPreviewMessage](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageList/GiphyPreviewMessage.tsx) |
264264

265+
### giphyVersion
266+
267+
The Giphy version to render - check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values.
268+
269+
| Type | Default |
270+
| --------- | -------------- |
271+
| string | 'fixed_height' |
272+
265273
### HeaderComponent
266274

267275
Custom UI component to render at the top of the `MessageList`.

docusaurus/docs/React/custom-code-examples/channel-search.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import CustomChannelSearch from '../assets/CustomChannelSearch.png';
99
## How-to Guide for Customizing ChannelSearch
1010

1111
In this example, we will customize the [`ChannelSearch`](../core-components/channel-list.mdx#channelsearch) component. Though this component can be used standalone, we will do our customization when it's established in the `ChannelList`. Here is a guide that outlines how to
12-
override the default `DropdownContainer` and `SearchResultItem` components, as well as use several other useful props.
12+
override the default `DropdownContainer`, `SearchResultItem`, and `SearchResultsHeader` components, as well as use several other useful props.
1313

1414
:::note
1515
A complete override of this component is possible by utilizing the [`ChannelSearch`](../core-components/channel-list.mdx#channelsearch) prop on `ChannelList`.
@@ -308,3 +308,34 @@ const additionalProps = {
308308
### Result:
309309
310310
<img src={CustomChannelSearch} alt='Custom Channel Search UI Component for Chat' width='700' />
311+
312+
### The searchFunction Prop:
313+
314+
By default the `ChannelSearch` component searches just for users. Use the `searchForChannels` prop to also search for channels.
315+
316+
To override the search method, completely use the `searchFunction` prop. This prop is useful, say, when you want to search just for channels
317+
and for only channels that the current logged in user is a member of. See the example below for this.
318+
319+
```jsx
320+
const customSearchFunction = async (props: ChannelSearchFunctionParams, event: { target: { value: SetStateAction<string>; }; }) => {
321+
const { setResults, setResultsOpen, setSearching, setQuery } = props;
322+
const { client } = useChatContext();
323+
324+
const filters = {
325+
name: { $autocomplete: event.target.value },
326+
members: { $in: client.userID }
327+
}
328+
329+
setSearching(true);
330+
setQuery(event.target.value);
331+
const channels = await chatClient.queryChannels(filters);
332+
setResults(channels);
333+
setResultsOpen(true);
334+
setSearching(false);
335+
};
336+
337+
<ChannelList
338+
showChannelSearch
339+
additionalChannelSearchProps={{searchFunction: customSearchFunction}}
340+
/>
341+
```
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
id: livestream-setup
3+
sidebar_position: 22
4+
title: Livestream Best Practices
5+
---
6+
import MarginInspector from '../assets/margin-inspector.png'
7+
import MessageHeight from '../assets/message-height.png'
8+
9+
Livestream chat UI poses several hard technological challenges since users can spend a few hours watching a certain event. For that period, the chat UI should be able to handle a constant stream of messages, reactions, and media attachments.
10+
11+
The React SDK offers a special component for that purpose - the `VirtualizedMessageList`. The component renders only the messages visible in the viewport and dynamically updates its contents as the user scrolls.
12+
This decreases browser memory usage and does not degrade the performance of the page even if the user receives thousands of messages in a single session.
13+
14+
In this article, we will go through the best practices and tweaks for configuring the `VirtualizedMessageList` to ensure a smooth user experience during a high message traffic.
15+
16+
## Get Started
17+
18+
The `VirtualizedMessageList` is mostly compatible with the non-virtualized `MessageList`, although not all properties are the same. The simplest configuration and placement are the same:
19+
20+
```tsx
21+
<Chat client={client}>
22+
<ChannelList />
23+
<Channel>
24+
<VirtualizedMessageList />
25+
<MessageInput />
26+
</Channel>
27+
</Chat>
28+
```
29+
30+
With this configuration, the virtualized list will look identical to the non-virtualized version. With the next few steps, we can configure the component for maximum performance.
31+
32+
## Disable the automatic scroll to bottom transition
33+
34+
By default, the `VirtualizedMessageList` will scroll down to display new messages using the `"smooth"` scroll behavior ([MDN link](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo#examples)). This works well for moderately busy chat rooms but can be unwieldy in chats with more than 2-3 incoming messages per second. A safer, snappier option is `"auto"`. With that setting, the list scrolls to the latest received message instantly.
35+
36+
```tsx
37+
<VirtualizedMessageList stickToBottomScrollBehavior="auto" />
38+
```
39+
40+
## Specify the default item height
41+
42+
The `VirtualizedMessageList` supports items with varying heights and automatically keeps track of the rendered item sizes, while estimating the not-yet-rendered sizes based on latest message during load. To optimize this further and minimize potential recalculations, set the `defaultItemHeight` to the height of your usual one-line message (If in doubt, use the developer tools inspector to determine the sizing).
43+
44+
<img src={MessageHeight} alt='Message Height' width='700' />
45+
46+
The element above is `58px` tall, so let's put that at the `defaultItemHeight` prop value:
47+
48+
```tsx
49+
<VirtualizedMessageList defaultItemHeight={58} />
50+
```
51+
52+
## Avoid vertical CSS margins
53+
If the custom Message component has vertical margins that affect its height, the message list might behave erratically (blinking, rendering white areas, etc).
54+
55+
This could be a potential pitfall if you're using a custom message component. The `VirtualizedMessageList` uses `getBoundingClientRect` ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect)) on the outermost message element.
56+
This method does not measure CSS margins, which are tricky to measure in the first place [due to collapsing](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing).
57+
If the custom Message component has vertical margins that affect its height, the message list might behave erratically (blinking, rendering white areas, etc).
58+
59+
Use your DOM inspector and look for any orange gaps between the message elements. See the screenshot below for example of headings with margins:
60+
61+
<img src={MarginInspector} alt='Margin Inspector' width='700' />
62+
63+
## Choose the right Giphy size
64+
65+
This practice is not unique to the virtualized message list but might help you build a more compact chat timeline and reduce the overall traffic for your users. By default, the Giphy attachments [use the original Giphy version image](https://developers.giphy.com/docs/api/schema#image-object). You can override that by setting the `giphyVersion` property of the `Channel` Component to a smaller one - use the keys [from the Giphy documentation](https://developers.giphy.com/docs/api/schema#image-object).
66+
67+
```tsx
68+
<Chat client={client}>
69+
<ChannelList />
70+
<Channel giphyVersion="fixed_height_small">
71+
<VirtualizedMessageList />
72+
<MessageInput />
73+
</Channel>
74+
</Chat>
75+
```
76+
77+
## Design reactions so that they don't change the message size
78+
79+
One final best practice: make sure that adding reactions to the message does not increase the message height if you're using a custom `Message` component. Good examples for such design would be the chat boxes of Twitch and Telegram.
80+
Avoiding that will make the message list appear more stable and less jumpy during high traffic.

docusaurus/docs/React/customization/message-ui.mdx

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,156 @@ export const CustomMessage = () => {
118118
};
119119
```
120120
121+
CustomMessage.scss:
122+
123+
```css
124+
.str-chat__li {
125+
margin: 0px;
126+
padding: 15px;
127+
position: relative;
128+
129+
&:hover {
130+
background: rgba(0, 0, 0, 0.03);
131+
.str-chat__message-text-inner {
132+
background: rgba(0, 0, 0, 0);
133+
}
134+
}
135+
}
136+
137+
.message-wrapper {
138+
display: flex;
139+
140+
&-content {
141+
display: flex;
142+
flex-direction: column;
143+
align-items: flex-start;
144+
width: 100%;
145+
}
146+
}
147+
148+
.message-header {
149+
display: flex;
150+
151+
&-name {
152+
font-family: Helvetica Neue, sans-serif;
153+
font-weight: 500;
154+
font-size: 11px;
155+
line-height: 120%;
156+
color: #858688;
157+
}
158+
159+
&-timestamp {
160+
font-family: Helvetica Neue, sans-serif;
161+
font-size: 11px;
162+
line-height: 120%;
163+
color: #858688;
164+
margin-left: 6px;
165+
}
166+
}
167+
168+
.str-chat__li:hover .str-chat__message-simple__actions {
169+
position: absolute;
170+
top: -14px;
171+
right: 20px;
172+
display: flex;
173+
align-items: center;
174+
justify-content: space-between;
175+
height: 24px;
176+
border-radius: 100px;
177+
background: white;
178+
border: 1px solid #e0e0e0;
179+
box-shadow: 0 2px 1px 0 rgba(0, 0, 0, 0.07);
180+
z-index: 1;
181+
padding: 0 4px 0;
182+
183+
&__action--reactions {
184+
display: flex;
185+
}
186+
187+
&__action--options {
188+
display: flex;
189+
}
190+
191+
&__action--thread {
192+
display: flex;
193+
}
194+
}
195+
196+
.str-chat__message-simple__actions {
197+
margin-top: 0;
198+
}
199+
200+
.str-chat__message-actions-box {
201+
top: initial;
202+
left: -100px;
203+
border-radius: 16px 16px 0 16px;
204+
}
205+
206+
.str-chat__message-text {
207+
display: flex;
208+
width: 100%;
209+
}
210+
211+
.str-chat__message-text-inner {
212+
position: relative;
213+
flex: 1;
214+
display: block;
215+
min-height: 32px;
216+
font-size: 15px;
217+
color: black;
218+
border-radius: 0;
219+
border: 0px;
220+
margin-left: 0;
221+
222+
p {
223+
font-family: Helvetica Neue, sans-serif;
224+
font-size: 15px;
225+
line-height: 18px;
226+
color: #000000;
227+
margin-bottom: 0;
228+
}
229+
}
230+
231+
.str-chat__message-replies-count-button {
232+
font-family: Helvetica Neue, sans-serif;
233+
font-weight: bold;
234+
font-size: 13px;
235+
text-align: right;
236+
color: #4e1d9d;
237+
}
238+
239+
.str-chat__simple-reactions-list {
240+
border-radius: 10px;
241+
}
242+
243+
.str-chat__reaction-selector {
244+
max-height: 40px;
245+
top: -58px;
246+
right: 20px;
247+
border-radius: 20px;
248+
background: white;
249+
box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.15);
250+
border: 1px solid #bed5e4;
251+
}
252+
253+
.str-chat__message-reactions-list-item__count {
254+
color: #000000;
255+
}
256+
257+
.str-chat__message-simple-status {
258+
right: 22px;
259+
}
260+
261+
.quoted-message-inner {
262+
margin-top: 10px;
263+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
264+
}
265+
266+
.str-chat__li .quoted-message.mine .quoted-message-inner {
267+
background: #ebebeb;
268+
}
269+
```
270+
121271
#### The Result:
122272
123273
<img src={CustomMessage} alt='Custom Message UI Component for Chat' width='700' />

0 commit comments

Comments
 (0)