Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![NPM](https://img.shields.io/npm/v/stream-chat-react-native.svg)](https://www.npmjs.com/package/stream-chat-react-native)
[![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)
[![Component Reference](https://img.shields.io/badge/docs-component%20reference-blue.svg)](https://getstream.io/chat/docs/sdk/reactnative)
![JS Bundle Size](https://img.shields.io/badge/js_bundle_size-1972%20KB-blue)
![JS Bundle Size](https://img.shields.io/badge/js_bundle_size-1974%20KB-blue)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { Platform } from 'react-native';
let MediaLibrary;

try {
MediaLibrary = require('expo-media-library');
MediaLibrary = require('expo-media-library/legacy');
} catch (e) {
// do nothing
try {
MediaLibrary = require('expo-media-library');
} catch (e) {
// do nothing
}
}

if (!MediaLibrary) {
Expand Down
8 changes: 6 additions & 2 deletions package/expo-package/src/optionalDependencies/getPhotos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import { getLocalAssetUri } from './getLocalAssetUri';
let MediaLibrary;

try {
MediaLibrary = require('expo-media-library');
MediaLibrary = require('expo-media-library/legacy');
} catch (e) {
// do nothing
try {
MediaLibrary = require('expo-media-library');
} catch (e) {
// do nothing
}
}

if (!MediaLibrary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { Platform } from 'react-native';
let MediaLibrary;

try {
MediaLibrary = require('expo-media-library');
MediaLibrary = require('expo-media-library/legacy');
} catch (e) {
// do nothing
try {
MediaLibrary = require('expo-media-library');
} catch (e) {
// do nothing
}
}

if (!MediaLibrary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { Platform } from 'react-native';
let MediaLibrary;

try {
MediaLibrary = require('expo-media-library');
MediaLibrary = require('expo-media-library/legacy');
} catch (e) {
// do nothing
try {
MediaLibrary = require('expo-media-library');
} catch (e) {
// do nothing
}
}

if (!MediaLibrary) {
Expand Down
4 changes: 2 additions & 2 deletions package/src/components/Attachment/FileAttachmentGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type FileAttachmentGroupPropsWithContext = Pick<MessageContextValue, 'fil
};

const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithContext) => {
const { files, message, styles: stylesProp = {} } = props;
const { files, styles: stylesProp = {} } = props;
const { Attachment } = useComponentsContext();

const {
Expand All @@ -32,7 +32,7 @@ const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithConte
<View style={[styles.container, {}, container, stylesProp.container]}>
{files.map((file, index) => (
<View
key={`file-by-attachment-group-${message.id}-${index}`}
key={`file-by-attachment-group-${index}`}
style={[styles.item, stylesProp.attachmentContainer, attachmentContainer]}
>
<Attachment attachment={file} />
Expand Down
2 changes: 1 addition & 1 deletion package/src/components/Attachment/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ const GalleryThumbnail = ({
accessibilityLabel={thumbnailAccessibilityLabel}
accessibilityRole='button'
disabled={preventPress}
key={`gallery-item-${message.id}/${colIndex}/${rowIndex}/${imagesAndVideos.length}`}
key={`gallery-item-${colIndex}/${rowIndex}`}
ref={thumbnailRef}
onLongPress={(event) => {
if (onLongPress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const MessageContentWithContext = (props: MessageContentPropsWithContext) => {
);
case 'attachments':
return otherAttachments.map((attachment, attachmentIndex) => (
<Attachment attachment={attachment} key={`${message.id}-${attachmentIndex}`} />
<Attachment attachment={attachment} key={`attachment-${attachmentIndex}`} />
));
case 'files':
return (
Expand All @@ -297,7 +297,7 @@ const MessageContentWithContext = (props: MessageContentPropsWithContext) => {
const pollId = message.poll_id;
const poll = pollId && client.polls.fromState(pollId);
return pollId && poll ? (
<Poll key={`poll_${message.poll_id}`} message={message} poll={poll} />
<Poll key={`poll_${messageContentOrderIndex}`} message={message} poll={poll} />
) : null;
}
case 'location':
Expand Down
55 changes: 54 additions & 1 deletion package/src/components/MessageList/MessageFlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ import { mergeThemes, useTheme } from '../../contexts/themeContext/ThemeContext'
import { ThreadContextValue, useThreadContext } from '../../contexts/threadContext/ThreadContext';

import { useStableCallback, useStateStore } from '../../hooks';
import { isVideoPlayerAvailable } from '../../native';
import { bumpOverlayLayoutRevision, useHasActiveId } from '../../state-store';
import { MessageInputHeightState } from '../../state-store/message-input-height-store';
import { primitives } from '../../theme';
import { FileTypes } from '../../types/types';
import { transitions } from '../../utils/animations/transitions';
import { MessageWrapper } from '../Message/MessageItemView/MessageWrapper';
import { excludeCanceledUploadNotifications } from '../Notifications/notificationFilters';
Expand Down Expand Up @@ -222,10 +224,61 @@ type MessageFlashListPropsWithContext = Pick<

const WAIT_FOR_SCROLL_TIMEOUT = 0;

// Classify an attachment bearing message by its primary shape so FlashList only
// recycles same shaped cells (means less work to rerender). Gallery/media is the
// heaviest subtree to mount, so we short circuit to it as soon as we see one gallery
// image/video nad this keeps gallery cells recycling only with other gallery cells,
// so the Gallery subtree reconciles on rebind instead of unmount & remount. Mirrors
// the attachment categorization in Message.
const getAttachmentItemType = (message: LocalMessage) => {
const attachments = message.attachments ?? [];
let hasGiphy = false;
let hasAudio = false;
let hasFile = false;
let hasCard = false;
for (const attachment of attachments) {
const isGalleryImage =
attachment.type === FileTypes.Image &&
!attachment.og_scrape_url &&
!attachment.title_link &&
(!!attachment.image_url || !!attachment.thumb_url);
const isGalleryVideo =
attachment.type === FileTypes.Video && !attachment.og_scrape_url && isVideoPlayerAvailable();
if (isGalleryImage || isGalleryVideo) {
return 'message-with-gallery';
}
if (attachment.type === FileTypes.Giphy) {
hasGiphy = true;
} else if (
attachment.type === FileTypes.Audio ||
attachment.type === FileTypes.VoiceRecording
) {
hasAudio = true;
} else if (attachment.type === FileTypes.File) {
hasFile = true;
} else if (attachment.og_scrape_url || attachment.title_link) {
hasCard = true;
}
}
if (hasGiphy) {
return 'message-with-giphy';
}
if (hasAudio) {
return 'message-with-audio';
}
if (hasFile) {
return 'message-with-file';
}
if (hasCard) {
return 'message-with-card';
}
return 'message-with-attachments';
};

const getItemTypeInternal = (message: LocalMessage) => {
if (message.type === 'regular') {
if ((message.attachments?.length ?? 0) > 0) {
return 'message-with-attachments';
return getAttachmentItemType(message);
}

if (message.poll_id) {
Expand Down