Skip to content

Commit a5aef62

Browse files
committed
Merge branch 'feat/flashlist-implementation' of github.com:GetStream/stream-chat-react-native into feat/flashlist-implementation
2 parents c44dde4 + 2f94dc8 commit a5aef62

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

package/src/components/MessageList/MessageFlashList.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,43 @@ type MessageListFlashListPropsWithContext = Pick<
183183

184184
const WAIT_FOR_SCROLL_TIMEOUT = 200;
185185

186+
const getItemTypeInternal = (message: LocalMessage) => {
187+
if (message.type === 'regular') {
188+
if ((message.attachments?.length ?? 0) > 0) {
189+
return 'message-with-attachments';
190+
}
191+
192+
if (message.poll_id) {
193+
return 'message-with-poll';
194+
}
195+
196+
if (message.quoted_message_id) {
197+
return 'message-with-quote';
198+
}
199+
200+
if (message.shared_location) {
201+
return 'message-with-shared-location';
202+
}
203+
204+
if (message.text) {
205+
const text = message.text;
206+
if (text.length <= 20) {
207+
return 'short-message-with-text';
208+
}
209+
210+
if (text.length <= 100) {
211+
return 'medium-message-with-text';
212+
}
213+
214+
return 'message-with-text';
215+
}
216+
217+
return 'message-with-nothing';
218+
}
219+
220+
return 'unresolvable-type';
221+
};
222+
186223
const MessageListFlashListWithContext = (props: MessageListFlashListPropsWithContext) => {
187224
const LoadingMoreRecentIndicator = props.threadList
188225
? InlineLoadingMoreRecentThreadIndicator
@@ -1024,6 +1061,11 @@ const MessageListFlashListWithContext = (props: MessageListFlashListPropsWithCon
10241061
[contentContainer],
10251062
);
10261063

1064+
const getItemType = useStableCallback((item: LocalMessage) => {
1065+
const type = getItemTypeInternal(item);
1066+
return client.userID === item.user?.id ? `own-${type}` : type;
1067+
});
1068+
10271069
if (loading) {
10281070
return (
10291071
<View style={[styles.container, { backgroundColor: white_snow }, container]}>
@@ -1045,6 +1087,8 @@ const MessageListFlashListWithContext = (props: MessageListFlashListPropsWithCon
10451087
<FlashList
10461088
contentContainerStyle={flatListContentContainerStyle}
10471089
data={processedMessageList}
1090+
drawDistance={1500}
1091+
getItemType={getItemType}
10481092
keyboardShouldPersistTaps='handled'
10491093
keyExtractor={keyExtractor}
10501094
ListFooterComponent={FooterComponent}

0 commit comments

Comments
 (0)