stream-chat-react-native-core 8.12.4 → 8.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Channel/Channel.js +1 -1
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js +69 -61
- package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +1 -7
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +30 -3
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Channel/Channel.js +1 -1
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/components/Channel/hooks/useMessageListPagination.js +69 -61
- package/lib/module/components/Channel/hooks/useMessageListPagination.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +1 -7
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/module/components/MessageList/MessageList.js +30 -3
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
- package/lib/typescript/components/Channel/hooks/useMessageListPagination.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts.map +1 -1
- package/lib/typescript/components/MessageList/MessageList.d.ts.map +1 -1
- package/lib/typescript/hooks/useTranslatedMessage.d.ts +1 -0
- package/lib/typescript/hooks/useTranslatedMessage.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/Channel/Channel.tsx +2 -1
- package/src/components/Channel/__tests__/useMessageListPagination.test.js +4 -4
- package/src/components/Channel/hooks/useMessageListPagination.tsx +2 -2
- package/src/components/ChannelList/hooks/usePaginatedChannels.ts +1 -8
- package/src/components/MessageList/MessageList.tsx +45 -3
- package/src/version.json +1 -1
|
@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
2
2
|
import {
|
|
3
3
|
FlatListProps,
|
|
4
4
|
FlatList as FlatListType,
|
|
5
|
+
LayoutChangeEvent,
|
|
5
6
|
ScrollViewProps,
|
|
6
7
|
StyleSheet,
|
|
7
8
|
View,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
ViewToken,
|
|
10
11
|
} from 'react-native';
|
|
11
12
|
|
|
13
|
+
import debounce from 'lodash/debounce';
|
|
12
14
|
import type { Channel, Event, LocalMessage, MessageResponse } from 'stream-chat';
|
|
13
15
|
|
|
14
16
|
import { useMessageList } from './hooks/useMessageList';
|
|
@@ -327,8 +329,8 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
327
329
|
|
|
328
330
|
const renderItem = useCallback(
|
|
329
331
|
({ item: message, index }: { item: LocalMessage; index: number }) => {
|
|
330
|
-
const previousMessage =
|
|
331
|
-
const nextMessage =
|
|
332
|
+
const previousMessage = processedMessageList[index + 1];
|
|
333
|
+
const nextMessage = processedMessageList[index - 1];
|
|
332
334
|
return (
|
|
333
335
|
<MessageWrapper
|
|
334
336
|
message={message}
|
|
@@ -337,7 +339,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
337
339
|
/>
|
|
338
340
|
);
|
|
339
341
|
},
|
|
340
|
-
[
|
|
342
|
+
[processedMessageList],
|
|
341
343
|
);
|
|
342
344
|
|
|
343
345
|
const messageListLengthBeforeUpdate = useRef(0);
|
|
@@ -1126,6 +1128,44 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
1126
1128
|
[additionalFlatListProps?.contentContainerStyle, contentContainer],
|
|
1127
1129
|
);
|
|
1128
1130
|
|
|
1131
|
+
const viewportHeightRef = useRef<number>(undefined);
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* This debounced callback makes sure that if the current number of messages do not
|
|
1135
|
+
* fill our screen, we load more messages continuously until we cover enough ground.
|
|
1136
|
+
*/
|
|
1137
|
+
const debouncedPrefillMessages = useMemo(
|
|
1138
|
+
() =>
|
|
1139
|
+
debounce(
|
|
1140
|
+
(viewportHeight: number, contentHeight: number) => {
|
|
1141
|
+
if (viewportHeight >= contentHeight) {
|
|
1142
|
+
maybeCallOnEndReached();
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
500,
|
|
1146
|
+
{
|
|
1147
|
+
leading: false,
|
|
1148
|
+
trailing: true,
|
|
1149
|
+
},
|
|
1150
|
+
),
|
|
1151
|
+
[maybeCallOnEndReached],
|
|
1152
|
+
);
|
|
1153
|
+
|
|
1154
|
+
const onContentSizeChange = useStableCallback((width: number, height: number) => {
|
|
1155
|
+
if (additionalFlatListProps?.onContentSizeChange) {
|
|
1156
|
+
additionalFlatListProps.onContentSizeChange(width, height);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
debouncedPrefillMessages(viewportHeightRef.current ?? 0, height);
|
|
1160
|
+
});
|
|
1161
|
+
|
|
1162
|
+
const onLayout = useStableCallback((event: LayoutChangeEvent) => {
|
|
1163
|
+
if (additionalFlatListProps?.onLayout) {
|
|
1164
|
+
additionalFlatListProps.onLayout(event);
|
|
1165
|
+
}
|
|
1166
|
+
viewportHeightRef.current = event.nativeEvent.layout.height;
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1129
1169
|
if (!FlatList) {
|
|
1130
1170
|
return null;
|
|
1131
1171
|
}
|
|
@@ -1168,6 +1208,8 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
1168
1208
|
*/
|
|
1169
1209
|
maintainVisibleContentPosition={maintainVisibleContentPosition}
|
|
1170
1210
|
maxToRenderPerBatch={30}
|
|
1211
|
+
onContentSizeChange={onContentSizeChange}
|
|
1212
|
+
onLayout={onLayout}
|
|
1171
1213
|
onMomentumScrollEnd={onUserScrollEvent}
|
|
1172
1214
|
onScroll={handleScroll}
|
|
1173
1215
|
onScrollBeginDrag={onScrollBeginDrag}
|
package/src/version.json
CHANGED