Skip to content

Commit 00d8d80

Browse files
authored
Merge pull request #1808 from GetStream/develop (v10.3.0)
2 parents d21a6bc + 1a8f241 commit 00d8d80

File tree

33 files changed

+656
-183
lines changed

33 files changed

+656
-183
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "React Contexts",
3-
"position": 9
3+
"position": 10
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Core Components",
3-
"position": 2
3+
"position": 3
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Custom Code Examples",
3-
"position": 7
3+
"position": 8
44
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
id: channel-list-infinite-scroll
3+
sidebar_position: 24
4+
title: Channel List Infinite Scroll
5+
keywords: [channel list, infinite scroll]
6+
---
7+
8+
import GHComponentLink from '../_docusaurus-components/GHComponentLink';
9+
10+
This example demonstrates how to implement infinite scroll with existing SDK components. By default, the SDK's `ChannelList` component uses `LoadMorePaginator` to load more channels into the list. More channels are loaded every time the `LoadMoreButton` is clicked. The infinite scroll instead loads more channels based on the channel list container's scroll position. The request to load more channels is automatically triggered, once the scroller approaches the bottom scroll threshold of the container.
11+
12+
## How to plug in the infinite scroll
13+
14+
The SDK provides own [`InfiniteScroll`](https://github.com/GetStream/stream-chat-react/blob/master/src/components/InfiniteScrollPaginator/InfiniteScroll.tsx) component. This component implements the [`PaginatorProps`](https://github.com/GetStream/stream-chat-react/blob/master/src/types/types.ts) interface. As this interface is implemented by the [`LoadMorePaginator`](https://github.com/GetStream/stream-chat-react/blob/master/src/components/LoadMore/LoadMorePaginator.ts) too, we can just pass the `InfiniteScroll` into the `ChannelList` prop `Paginator`.
15+
16+
```tsx
17+
import {
18+
ChannelList,
19+
InfiniteScroll,
20+
} from 'stream-chat-react';
21+
22+
<ChannelList filters={filters} sort={sort} options={options}
23+
Paginator={InfiniteScroll}
24+
showChannelSearch
25+
/>
26+
```
27+
28+
If you would like to adjust the configuration parameters like `threshold`, `reverse` (`PaginatorProps`) or `useCapture`, etc. (`InfiniteScrollProps`), you can create a wrapper component where these props can be set:
29+
30+
```tsx
31+
import {
32+
ChannelList,
33+
InfiniteScroll,
34+
InfiniteScrollProps
35+
} from 'stream-chat-react';
36+
37+
38+
const Paginator = (props: InfiniteScrollProps) => <InfiniteScroll {...props} threshold={50} />;
39+
40+
...
41+
<ChannelList filters={filters} sort={sort} options={options}
42+
Paginator={Paginator}
43+
showChannelSearch
44+
/>
45+
```
46+
47+
Especially the `threshold` prop may need to be set as the default is 250px. That may be too soon to load more channels.
48+
49+
## What to take into consideration
50+
51+
For the infinite scroll to work, the element containing the `ChannelPreview` list has to be forced to display the scroll bar with the initial channel list load. This is achieved by:
52+
53+
**1. adjusting the initial number of loaded channels**
54+
55+
Set a reasonable number of channels to be initially loaded. If loading 10 channels leads to them being visible without having to scroll, then increase the number to e.g. 15:
56+
57+
```tsx
58+
import type { ChannelOptions } from 'stream-chat';
59+
const options: ChannelOptions = { state: true, presence: true, limit: 15 };
60+
```
61+
62+
**2. adjusting the container height**
63+
64+
You can change the container height so that not all channels are visible at once. You should target the container with class `.str-chat__channel-list-messenger-react__main`
65+
66+
```css
67+
.str-chat__channel-list-messenger-react__main {
68+
max-height: 50%;
69+
}
70+
```
71+
72+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "General Customization",
3-
"position": 5
3+
"position": 6
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Custom Hooks",
3-
"position": 10
3+
"position": 11
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Message Components",
3-
"position": 3
3+
"position": 4
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Message Input Components",
3-
"position": 4
3+
"position": 5
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Resources",
3-
"position": 12
3+
"position": 14
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Theming and CSS",
3-
"position": 6
3+
"position": 7
44
}

0 commit comments

Comments
Β (0)