Skip to content

Commit 457c694

Browse files
khushal87oliverlaz
andauthored
fix: add a log that complains for removal for mvcp package on RN version <0.72 (#2724)
* fix: add a log that complains for removal for mvcp package on RN version <0.72 * fix: add a log that complains for removal for mvcp package on RN version <0.72 * fix: build issues * fix: add variable under the if block Co-authored-by: Oliver Lazoroski <[email protected]> * fix: log --------- Co-authored-by: Oliver Lazoroski <[email protected]>
1 parent 76cb67d commit 457c694

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
import { FlatList as DefaultFlatList, Platform } from 'react-native';
12
let FlatList;
23

3-
try {
4-
FlatList = require('@stream-io/flat-list-mvcp').FlatList;
5-
} catch (e) {
6-
console.log("@stream-io/flat-list-mvcp not found, using react-native's FlatList");
4+
5+
if (Platform.constants.reactNativeVersion.minor < 72) {
6+
const upgradeLog =
7+
"'@stream-io/flat-list-mvcp' is deprecated, please upgrade your react-native version to >0.71 to get same the benefits on the default FlatList and uninstall the package.";
8+
try {
9+
FlatList = require('@stream-io/flat-list-mvcp').FlatList;
10+
console.log(upgradeLog);
11+
} catch (error) {
12+
console.log(
13+
`@stream-io/flat-list-mvcp not found, using react-native's FlatList. This library is used to achieve bi-directional infinite scrolling on lower react native versions. ${upgradeLog}`,
14+
);
15+
FlatList = require('react-native').FlatList;
16+
}
17+
} else {
18+
FlatList = DefaultFlatList;
719
}
20+
21+
export { FlatList };

package/src/contexts/messagesContext/MessagesContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { PropsWithChildren, useContext } from 'react';
22

3-
import { FlatList, PressableProps } from 'react-native';
3+
import { PressableProps } from 'react-native';
44

55
import type { Attachment, ChannelState, MessageResponse } from 'stream-chat';
66

@@ -64,6 +64,7 @@ import type { SuggestionCommand } from '../suggestionsContext/SuggestionsContext
6464
import type { DeepPartial } from '../themeContext/ThemeContext';
6565
import type { Theme } from '../themeContext/utils/theme';
6666
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
67+
import { FlatList } from '../../native';
6768

6869
import { isTestEnvironment } from '../utils/isTestEnvironment';
6970

@@ -118,7 +119,7 @@ export type MessagesContextValue<
118119
* Defaults to: https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/FileIcon.tsx
119120
*/
120121
FileAttachmentIcon: React.ComponentType<FileIconProps>;
121-
FlatList: typeof FlatList;
122+
FlatList: typeof FlatList | undefined;
122123
/**
123124
* UI component to display image attachments
124125
* Defaults to: [Gallery](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Gallery.tsx)

package/src/native.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export let compressImage: CompressImage = fail;
2525
type DeleteFile = ({ uri }: { uri: string }) => Promise<boolean> | never;
2626
export let deleteFile: DeleteFile = fail;
2727

28-
export let FlatList = DefaultFlatList;
28+
export let FlatList: typeof DefaultFlatList | undefined = undefined;
2929

3030
type GetLocalAssetUri = (uriOrAssetId: string) => Promise<string | undefined> | never;
3131
export let getLocalAssetUri: GetLocalAssetUri = fail;
@@ -309,7 +309,7 @@ export const registerNativeHandlers = (handlers: Handlers) => {
309309
deleteFile = handlers.deleteFile;
310310
}
311311

312-
if (handlers.FlatList) {
312+
if (handlers.FlatList !== undefined) {
313313
FlatList = handlers.FlatList;
314314
}
315315

0 commit comments

Comments
 (0)