|
8 | 8 | ViewToken, |
9 | 9 | } from 'react-native'; |
10 | 10 |
|
11 | | -import { FlashListProps, FlashListRef } from '@shopify/flash-list'; |
| 11 | +import type { FlashListProps, FlashListRef } from '@shopify/flash-list'; |
12 | 12 | import type { Channel, Event, LocalMessage, MessageResponse } from 'stream-chat'; |
13 | 13 |
|
14 | 14 | import { useMessageList } from './hooks/useMessageList'; |
@@ -44,19 +44,9 @@ import { mergeThemes, ThemeProvider, useTheme } from '../../contexts/themeContex |
44 | 44 | import { ThreadContextValue, useThreadContext } from '../../contexts/threadContext/ThreadContext'; |
45 | 45 |
|
46 | 46 | import { useStableCallback } from '../../hooks'; |
| 47 | +import { getFlashList } from '../../native'; |
47 | 48 | import { FileTypes } from '../../types/types'; |
48 | 49 |
|
49 | | -// @ts-expect-error - FlashList is not defined in the global scope |
50 | | -let FlashList; |
51 | | - |
52 | | -try { |
53 | | - FlashList = require('@shopify/flash-list').FlashList; |
54 | | -} catch (e) { |
55 | | - console.error( |
56 | | - 'The package @shopify/flash-list is not installed. Installing this package will enable the use of the FlashList component.', |
57 | | - ); |
58 | | -} |
59 | | - |
60 | 50 | const keyExtractor = (item: LocalMessage) => { |
61 | 51 | if (item.id) { |
62 | 52 | return item.id; |
@@ -92,7 +82,7 @@ const getPreviousLastMessage = (messages: LocalMessage[], newMessage?: MessageRe |
92 | 82 | return previousLastMessage; |
93 | 83 | }; |
94 | 84 |
|
95 | | -type MessageListFlashListPropsWithContext = Pick< |
| 85 | +type MessageFlashListPropsWithContext = Pick< |
96 | 86 | AttachmentPickerContextValue, |
97 | 87 | 'closePicker' | 'selectedPicker' | 'setSelectedPicker' |
98 | 88 | > & |
@@ -251,7 +241,7 @@ const getItemTypeInternal = (message: LocalMessage) => { |
251 | 241 | return 'unresolvable-type'; |
252 | 242 | }; |
253 | 243 |
|
254 | | -const MessageListFlashListWithContext = (props: MessageListFlashListPropsWithContext) => { |
| 244 | +const MessageFlashListWithContext = (props: MessageFlashListPropsWithContext) => { |
255 | 245 | const LoadingMoreRecentIndicator = props.threadList |
256 | 246 | ? InlineLoadingMoreRecentThreadIndicator |
257 | 247 | : InlineLoadingMoreRecentIndicator; |
@@ -1124,7 +1114,8 @@ const MessageListFlashListWithContext = (props: MessageListFlashListPropsWithCon |
1124 | 1114 | ); |
1125 | 1115 | } |
1126 | 1116 |
|
1127 | | - // @ts-expect-error - FlashList is not defined in the global scope |
| 1117 | + const FlashList = getFlashList(); |
| 1118 | + |
1128 | 1119 | if (!FlashList) { |
1129 | 1120 | throw new Error( |
1130 | 1121 | 'The package @shopify/flash-list is not installed. Installing this package will enable the use of the FlashList component.', |
@@ -1190,9 +1181,9 @@ const MessageListFlashListWithContext = (props: MessageListFlashListPropsWithCon |
1190 | 1181 | ); |
1191 | 1182 | }; |
1192 | 1183 |
|
1193 | | -export type MessageListFlashListProps = Partial<MessageListFlashListPropsWithContext>; |
| 1184 | +export type MessageFlashListProps = Partial<MessageFlashListPropsWithContext>; |
1194 | 1185 |
|
1195 | | -export const MessageListFlashList = (props: MessageListFlashListProps) => { |
| 1186 | +export const MessageFlashList = (props: MessageFlashListProps) => { |
1196 | 1187 | const { closePicker, selectedPicker, setSelectedPicker } = useAttachmentPickerContext(); |
1197 | 1188 | const { |
1198 | 1189 | channel, |
@@ -1239,7 +1230,7 @@ export const MessageListFlashList = (props: MessageListFlashListProps) => { |
1239 | 1230 | const { loadMoreRecentThread, loadMoreThread, thread, threadInstance } = useThreadContext(); |
1240 | 1231 |
|
1241 | 1232 | return ( |
1242 | | - <MessageListFlashListWithContext |
| 1233 | + <MessageFlashListWithContext |
1243 | 1234 | {...{ |
1244 | 1235 | channel, |
1245 | 1236 | channelUnreadState, |
|
0 commit comments