Skip to content

Commit 3300425

Browse files
authored
fix: flashlist fixes (#3505)
## 🎯 Goal This PR restores FlashList as a truly optional dependency by removing the top-level runtime import path that made `@shopify/flash-list` effectively mandatory at SDK startup. It also brings `FlashList` in line with the existing `FlatList` overlay behavior by applying the same `message-overlay` close correction when the list viewport height changes, so context menu closing stays aligned during keyboard/composer size changes. ## 🛠 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
1 parent 5feeccb commit 3300425

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

package/src/components/MessageList/MessageFlashList.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
import Animated, { LinearTransition } from 'react-native-reanimated';
1212

13-
import { FlashListProps, FlashListRef, useFlashListContext } from '@shopify/flash-list';
13+
import type { FlashListProps, FlashListRef } from '@shopify/flash-list';
1414
import type { Channel, Event, LocalMessage, MessageResponse } from 'stream-chat';
1515

1616
import { useMessageList } from './hooks/useMessageList';
@@ -53,14 +53,20 @@ import { mergeThemes, useTheme } from '../../contexts/themeContext/ThemeContext'
5353
import { ThreadContextValue, useThreadContext } from '../../contexts/threadContext/ThreadContext';
5454

5555
import { useStableCallback, useStateStore } from '../../hooks';
56+
import { bumpOverlayLayoutRevision } from '../../state-store';
5657
import { MessageInputHeightState } from '../../state-store/message-input-height-store';
5758
import { primitives } from '../../theme';
5859
import { MessageWrapper } from '../Message/MessageItemView/MessageWrapper';
5960

61+
type FlashListContextApi = { getRef?: () => FlashListRef<LocalMessage> | null } | undefined;
62+
6063
let FlashList;
64+
let useFlashListContext: () => FlashListContextApi = () => undefined;
6165

6266
try {
63-
FlashList = require('@shopify/flash-list').FlashList;
67+
const flashListModule = require('@shopify/flash-list');
68+
FlashList = flashListModule.FlashList;
69+
useFlashListContext = flashListModule.useFlashListContext;
6470
} catch {
6571
FlashList = undefined;
6672
}
@@ -996,6 +1002,9 @@ const MessageFlashListWithContext = (props: MessageFlashListPropsWithContext) =>
9961002
return;
9971003
}
9981004

1005+
const closeCorrectionDeltaY = height - currentListHeightRef.current;
1006+
bumpOverlayLayoutRevision(closeCorrectionDeltaY);
1007+
9991008
const changedBy = currentListHeightRef.current - height;
10001009
flashListRef.current?.getNativeScrollRef()?.setNativeProps({
10011010
contentOffset: { x: 0, y: flashListRef.current?.getAbsoluteLastScrollOffset() + changedBy },
@@ -1132,7 +1141,7 @@ const FlashListFooterTypingAdapter = ({
11321141
const typingUsersLengthRef = useRef<number>(typingUsers.length);
11331142

11341143
useEffect(() => {
1135-
const listApi = api?.getRef();
1144+
const listApi = api?.getRef?.();
11361145

11371146
if (!enabled || !listApi) {
11381147
return;

0 commit comments

Comments
 (0)