Skip to content

Commit 0439f6a

Browse files
committed
fix: change message info bottom sheet modal
1 parent 7f0fe8a commit 0439f6a

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
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 & 10 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 {
@@ -130,6 +130,7 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
130130
} = useTheme();
131131
const { t } = useTranslationContext();
132132
const { setThread } = useStreamChatContext();
133+
const [modalVisible, setModalVisible] = useState(false);
133134
const [selectedMessage, setSelectedMessage] = useState<LocalMessage | undefined>(undefined);
134135

135136
const [channel, setChannel] = useState<StreamChatChannel | undefined>(channelFromProp);
@@ -186,15 +187,14 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
186187
[channel, navigation, setThread],
187188
);
188189

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

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

199199
const messageActions = useCallback(
200200
(params: MessageActionsParams) => {
@@ -249,7 +249,13 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
249249
)}
250250
<AITypingIndicatorView channel={channel} />
251251
<MessageInput />
252-
<MessageInfoBottomSheet message={selectedMessage} ref={messageInfoBottomSheetRef} />
252+
{modalVisible && (
253+
<MessageInfoBottomSheet
254+
visible={modalVisible}
255+
message={selectedMessage}
256+
onClose={handleMessageInfoClose}
257+
/>
258+
)}
253259
</Channel>
254260
</View>
255261
);

0 commit comments

Comments
 (0)