Skip to content

Commit bf63820

Browse files
isekovanicStream-SDK-BotStream Botszuperaz
authored
Next Release (#3701)
## 🎯 Goal <!-- Describe why we are making this change --> ## πŸ›  Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## πŸ§ͺ Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## β˜‘οΈ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android --------- Co-authored-by: Stream SDK Bot <60655709+Stream-SDK-Bot@users.noreply.github.com> Co-authored-by: Stream Bot <runner@runnervmkkn4f.dxzc3wllrnselczynunk3nwtgh.cx.internal.cloudapp.net> Co-authored-by: Zita Szupera <zita.szupera@getstream.io>
2 parents e3022d8 + 8502453 commit bf63820

9 files changed

Lines changed: 84 additions & 15 deletions

File tree

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![NPM](https://img.shields.io/npm/v/stream-chat-react-native.svg)](https://www.npmjs.com/package/stream-chat-react-native)
1111
[![Build Status](https://github.com/GetStream/stream-chat-react-native/actions/workflows/release.yml/badge.svg)](https://github.com/GetStream/stream-chat-react-native/actions)
1212
[![Component Reference](https://img.shields.io/badge/docs-component%20reference-blue.svg)](https://getstream.io/chat/docs/sdk/reactnative)
13-
![JS Bundle Size](https://img.shields.io/badge/js_bundle_size-1972%20KB-blue)
13+
![JS Bundle Size](https://img.shields.io/badge/js_bundle_size-1974%20KB-blue)
1414

1515
<img align="right" src="https://getstream.imgix.net/images/ios-chat-tutorial/iphone_chat_art@3x.png?auto=format,enhance" width="50%" />
1616

β€Žpackage/expo-package/src/optionalDependencies/getLocalAssetUri.tsβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { Platform } from 'react-native';
33
let MediaLibrary;
44

55
try {
6-
MediaLibrary = require('expo-media-library');
6+
MediaLibrary = require('expo-media-library/legacy');
77
} catch (e) {
8-
// do nothing
8+
try {
9+
MediaLibrary = require('expo-media-library');
10+
} catch (e) {
11+
// do nothing
12+
}
913
}
1014

1115
if (!MediaLibrary) {

β€Žpackage/expo-package/src/optionalDependencies/getPhotos.tsβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ import { getLocalAssetUri } from './getLocalAssetUri';
1010
let MediaLibrary;
1111

1212
try {
13-
MediaLibrary = require('expo-media-library');
13+
MediaLibrary = require('expo-media-library/legacy');
1414
} catch (e) {
15-
// do nothing
15+
try {
16+
MediaLibrary = require('expo-media-library');
17+
} catch (e) {
18+
// do nothing
19+
}
1620
}
1721

1822
if (!MediaLibrary) {

β€Žpackage/expo-package/src/optionalDependencies/iOS14RefreshGallerySelection.tsβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { Platform } from 'react-native';
33
let MediaLibrary;
44

55
try {
6-
MediaLibrary = require('expo-media-library');
6+
MediaLibrary = require('expo-media-library/legacy');
77
} catch (e) {
8-
// do nothing
8+
try {
9+
MediaLibrary = require('expo-media-library');
10+
} catch (e) {
11+
// do nothing
12+
}
913
}
1014

1115
if (!MediaLibrary) {

β€Žpackage/expo-package/src/optionalDependencies/oniOS14GalleryLibrarySelectionChange.tsβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { Platform } from 'react-native';
33
let MediaLibrary;
44

55
try {
6-
MediaLibrary = require('expo-media-library');
6+
MediaLibrary = require('expo-media-library/legacy');
77
} catch (e) {
8-
// do nothing
8+
try {
9+
MediaLibrary = require('expo-media-library');
10+
} catch (e) {
11+
// do nothing
12+
}
913
}
1014

1115
if (!MediaLibrary) {

β€Žpackage/src/components/Attachment/FileAttachmentGroup.tsxβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type FileAttachmentGroupPropsWithContext = Pick<MessageContextValue, 'fil
1717
};
1818

1919
const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithContext) => {
20-
const { files, message, styles: stylesProp = {} } = props;
20+
const { files, styles: stylesProp = {} } = props;
2121
const { Attachment } = useComponentsContext();
2222

2323
const {
@@ -32,7 +32,7 @@ const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithConte
3232
<View style={[styles.container, {}, container, stylesProp.container]}>
3333
{files.map((file, index) => (
3434
<View
35-
key={`file-by-attachment-group-${message.id}-${index}`}
35+
key={`file-by-attachment-group-${index}`}
3636
style={[styles.item, stylesProp.attachmentContainer, attachmentContainer]}
3737
>
3838
<Attachment attachment={file} />

β€Žpackage/src/components/Attachment/Gallery.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ const GalleryThumbnail = ({
272272
accessibilityLabel={thumbnailAccessibilityLabel}
273273
accessibilityRole='button'
274274
disabled={preventPress}
275-
key={`gallery-item-${message.id}/${colIndex}/${rowIndex}/${imagesAndVideos.length}`}
275+
key={`gallery-item-${colIndex}/${rowIndex}`}
276276
ref={thumbnailRef}
277277
onLongPress={(event) => {
278278
if (onLongPress) {

β€Žpackage/src/components/Message/MessageItemView/MessageContent.tsxβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ const MessageContentWithContext = (props: MessageContentPropsWithContext) => {
281281
);
282282
case 'attachments':
283283
return otherAttachments.map((attachment, attachmentIndex) => (
284-
<Attachment attachment={attachment} key={`${message.id}-${attachmentIndex}`} />
284+
<Attachment attachment={attachment} key={`attachment-${attachmentIndex}`} />
285285
));
286286
case 'files':
287287
return (
@@ -297,7 +297,7 @@ const MessageContentWithContext = (props: MessageContentPropsWithContext) => {
297297
const pollId = message.poll_id;
298298
const poll = pollId && client.polls.fromState(pollId);
299299
return pollId && poll ? (
300-
<Poll key={`poll_${message.poll_id}`} message={message} poll={poll} />
300+
<Poll key={`poll_${messageContentOrderIndex}`} message={message} poll={poll} />
301301
) : null;
302302
}
303303
case 'location':

β€Žpackage/src/components/MessageList/MessageFlashList.tsxβ€Ž

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ import { mergeThemes, useTheme } from '../../contexts/themeContext/ThemeContext'
5555
import { ThreadContextValue, useThreadContext } from '../../contexts/threadContext/ThreadContext';
5656

5757
import { useStableCallback, useStateStore } from '../../hooks';
58+
import { isVideoPlayerAvailable } from '../../native';
5859
import { bumpOverlayLayoutRevision, useHasActiveId } from '../../state-store';
5960
import { MessageInputHeightState } from '../../state-store/message-input-height-store';
6061
import { primitives } from '../../theme';
62+
import { FileTypes } from '../../types/types';
6163
import { transitions } from '../../utils/animations/transitions';
6264
import { MessageWrapper } from '../Message/MessageItemView/MessageWrapper';
6365
import { excludeCanceledUploadNotifications } from '../Notifications/notificationFilters';
@@ -222,10 +224,61 @@ type MessageFlashListPropsWithContext = Pick<
222224

223225
const WAIT_FOR_SCROLL_TIMEOUT = 0;
224226

227+
// Classify an attachment bearing message by its primary shape so FlashList only
228+
// recycles same shaped cells (means less work to rerender). Gallery/media is the
229+
// heaviest subtree to mount, so we short circuit to it as soon as we see one gallery
230+
// image/video nad this keeps gallery cells recycling only with other gallery cells,
231+
// so the Gallery subtree reconciles on rebind instead of unmount & remount. Mirrors
232+
// the attachment categorization in Message.
233+
const getAttachmentItemType = (message: LocalMessage) => {
234+
const attachments = message.attachments ?? [];
235+
let hasGiphy = false;
236+
let hasAudio = false;
237+
let hasFile = false;
238+
let hasCard = false;
239+
for (const attachment of attachments) {
240+
const isGalleryImage =
241+
attachment.type === FileTypes.Image &&
242+
!attachment.og_scrape_url &&
243+
!attachment.title_link &&
244+
(!!attachment.image_url || !!attachment.thumb_url);
245+
const isGalleryVideo =
246+
attachment.type === FileTypes.Video && !attachment.og_scrape_url && isVideoPlayerAvailable();
247+
if (isGalleryImage || isGalleryVideo) {
248+
return 'message-with-gallery';
249+
}
250+
if (attachment.type === FileTypes.Giphy) {
251+
hasGiphy = true;
252+
} else if (
253+
attachment.type === FileTypes.Audio ||
254+
attachment.type === FileTypes.VoiceRecording
255+
) {
256+
hasAudio = true;
257+
} else if (attachment.type === FileTypes.File) {
258+
hasFile = true;
259+
} else if (attachment.og_scrape_url || attachment.title_link) {
260+
hasCard = true;
261+
}
262+
}
263+
if (hasGiphy) {
264+
return 'message-with-giphy';
265+
}
266+
if (hasAudio) {
267+
return 'message-with-audio';
268+
}
269+
if (hasFile) {
270+
return 'message-with-file';
271+
}
272+
if (hasCard) {
273+
return 'message-with-card';
274+
}
275+
return 'message-with-attachments';
276+
};
277+
225278
const getItemTypeInternal = (message: LocalMessage) => {
226279
if (message.type === 'regular') {
227280
if ((message.attachments?.length ?? 0) > 0) {
228-
return 'message-with-attachments';
281+
return getAttachmentItemType(message);
229282
}
230283

231284
if (message.poll_id) {

0 commit comments

Comments
Β (0)