Skip to content

Commit 3e21355

Browse files
authored
fix: change message info bottom sheet modal (#3302)
1 parent f1f208a commit 3e21355

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

examples/SampleApp/src/components/MessageInfoBottomSheet.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import React, { useMemo } from 'react';
2-
import BottomSheet, { BottomSheetFlatList } from '@gorhom/bottom-sheet';
3-
import { BottomSheetView } from '@gorhom/bottom-sheet';
42
import {
53
Avatar,
4+
BottomSheetModal,
65
useChatContext,
76
useMessageDeliveredData,
87
useMessageReadData,
98
useTheme,
109
} from 'stream-chat-react-native';
1110
import { LocalMessage, UserResponse } from 'stream-chat';
12-
import { StyleSheet, Text, View } from 'react-native';
11+
import { FlatList, StyleSheet, Text, View } from 'react-native';
1312

1413
const renderUserItem = ({ item }: { item: UserResponse }) => (
1514
<View style={styles.userItem}>
@@ -24,10 +23,12 @@ const renderEmptyText = ({ text }: { text: string }) => (
2423

2524
export const MessageInfoBottomSheet = ({
2625
message,
27-
ref,
26+
visible,
27+
onClose,
2828
}: {
2929
message?: LocalMessage;
30-
ref: React.RefObject<BottomSheet | null>;
30+
visible: boolean;
31+
onClose: () => void;
3132
}) => {
3233
const {
3334
theme: { colors },
@@ -45,26 +46,26 @@ export const MessageInfoBottomSheet = ({
4546
}, [readStatus, client?.user?.id]);
4647

4748
return (
48-
<BottomSheet enablePanDownToClose ref={ref} index={-1} snapPoints={['50%']}>
49-
<BottomSheetView style={[styles.container, { backgroundColor: colors.white_smoke }]}>
49+
<BottomSheetModal visible={visible} onClose={onClose}>
50+
<View style={[styles.container, { backgroundColor: colors.white_smoke }]}>
5051
<Text style={styles.title}>Read</Text>
51-
<BottomSheetFlatList
52+
<FlatList
5253
data={otherReadUsers}
5354
renderItem={renderUserItem}
5455
keyExtractor={(item) => item.id}
5556
style={styles.flatList}
5657
ListEmptyComponent={renderEmptyText({ text: 'No one has read this message.' })}
5758
/>
5859
<Text style={styles.title}>Delivered</Text>
59-
<BottomSheetFlatList
60+
<FlatList
6061
data={otherDeliveredToUsers}
6162
renderItem={renderUserItem}
6263
keyExtractor={(item) => item.id}
6364
style={styles.flatList}
6465
ListEmptyComponent={renderEmptyText({ text: 'The message was not delivered to anyone.' })}
6566
/>
66-
</BottomSheetView>
67-
</BottomSheet>
67+
</View>
68+
</BottomSheetModal>
6869
);
6970
};
7071

examples/SampleApp/src/screens/ChannelScreen.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useRef, useState } from 'react';
1+
import React, { useCallback, useEffect, useState } from 'react';
22
import type { LocalMessage, Channel as StreamChatChannel } from 'stream-chat';
33
import { RouteProp, useFocusEffect, useNavigation } from '@react-navigation/native';
44
import {
@@ -33,7 +33,6 @@ import { channelMessageActions } from '../utils/messageActions.tsx';
3333
import { MessageLocation } from '../components/LocationSharing/MessageLocation.tsx';
3434
import { useStreamChatContext } from '../context/StreamChatContext.tsx';
3535
import { CustomAttachmentPickerSelectionBar } from '../components/AttachmentPickerSelectionBar.tsx';
36-
import BottomSheet from '@gorhom/bottom-sheet';
3736
import { MessageInfoBottomSheet } from '../components/MessageInfoBottomSheet.tsx';
3837

3938
export type ChannelScreenNavigationProp = NativeStackNavigationProp<
@@ -130,6 +129,7 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
130129
} = useTheme();
131130
const { t } = useTranslationContext();
132131
const { setThread } = useStreamChatContext();
132+
const [modalVisible, setModalVisible] = useState(false);
133133
const [selectedMessage, setSelectedMessage] = useState<LocalMessage | undefined>(undefined);
134134

135135
const [channel, setChannel] = useState<StreamChatChannel | undefined>(channelFromProp);
@@ -186,15 +186,14 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
186186
[channel, navigation, setThread],
187187
);
188188

189-
const messageInfoBottomSheetRef = useRef<BottomSheet>(null);
189+
const handleMessageInfo = useCallback((message: LocalMessage) => {
190+
setSelectedMessage(message);
191+
setModalVisible(true);
192+
}, []);
190193

191-
const handleMessageInfo = useCallback(
192-
(message: LocalMessage) => {
193-
setSelectedMessage(message);
194-
messageInfoBottomSheetRef.current?.snapToIndex(1);
195-
},
196-
[messageInfoBottomSheetRef],
197-
);
194+
const handleMessageInfoClose = useCallback(() => {
195+
setModalVisible(false);
196+
}, []);
198197

199198
const messageActions = useCallback(
200199
(params: MessageActionsParams) => {
@@ -249,7 +248,13 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
249248
)}
250249
<AITypingIndicatorView channel={channel} />
251250
<MessageInput />
252-
<MessageInfoBottomSheet message={selectedMessage} ref={messageInfoBottomSheetRef} />
251+
{modalVisible && (
252+
<MessageInfoBottomSheet
253+
visible={modalVisible}
254+
message={selectedMessage}
255+
onClose={handleMessageInfoClose}
256+
/>
257+
)}
253258
</Channel>
254259
</View>
255260
);

0 commit comments

Comments
 (0)