1- import React , { useCallback , useEffect , useState } from 'react' ;
1+ import React , { useCallback , useEffect , useRef , useState } from 'react' ;
22import type { LocalMessage , Channel as StreamChatChannel } from 'stream-chat' ;
33import { RouteProp , useFocusEffect , useNavigation } from '@react-navigation/native' ;
44import {
@@ -33,6 +33,8 @@ import { channelMessageActions } from '../utils/messageActions.tsx';
3333import { MessageLocation } from '../components/LocationSharing/MessageLocation.tsx' ;
3434import { useStreamChatContext } from '../context/StreamChatContext.tsx' ;
3535import { CustomAttachmentPickerSelectionBar } from '../components/AttachmentPickerSelectionBar.tsx' ;
36+ import BottomSheet from '@gorhom/bottom-sheet' ;
37+ import { MessageInfoBottomSheet } from '../components/MessageInfoBottomSheet.tsx' ;
3638
3739export type ChannelScreenNavigationProp = NativeStackNavigationProp <
3840 StackNavigatorParamList ,
@@ -115,19 +117,20 @@ const ChannelHeader: React.FC<ChannelHeaderProps> = ({ channel }) => {
115117
116118// Either provide channel or channelId.
117119export const ChannelScreen : React . FC < ChannelScreenProps > = ( {
120+ navigation,
118121 route : {
119122 params : { channel : channelFromProp , channelId, messageId } ,
120123 } ,
121124} ) => {
122125 const { chatClient, messageListImplementation, messageListMode, messageListPruning } =
123126 useAppContext ( ) ;
124- const navigation = useNavigation ( ) ;
125127 const { bottom } = useSafeAreaInsets ( ) ;
126128 const {
127129 theme : { colors } ,
128130 } = useTheme ( ) ;
129131 const { t } = useTranslationContext ( ) ;
130132 const { setThread } = useStreamChatContext ( ) ;
133+ const [ selectedMessage , setSelectedMessage ] = useState < LocalMessage | undefined > ( undefined ) ;
131134
132135 const [ channel , setChannel ] = useState < StreamChatChannel | undefined > ( channelFromProp ) ;
133136
@@ -170,6 +173,9 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
170173
171174 const onThreadSelect = useCallback (
172175 ( thread : LocalMessage | null ) => {
176+ if ( ! thread || ! channel ) {
177+ return ;
178+ }
173179 setSelectedThread ( thread ) ;
174180 setThread ( thread ) ;
175181 navigation . navigate ( 'ThreadScreen' , {
@@ -180,6 +186,16 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
180186 [ channel , navigation , setThread ] ,
181187 ) ;
182188
189+ const messageInfoBottomSheetRef = useRef < BottomSheet > ( null ) ;
190+
191+ const handleMessageInfo = useCallback (
192+ ( message : LocalMessage ) => {
193+ setSelectedMessage ( message ) ;
194+ messageInfoBottomSheetRef . current ?. snapToIndex ( 1 ) ;
195+ } ,
196+ [ messageInfoBottomSheetRef ] ,
197+ ) ;
198+
183199 const messageActions = useCallback (
184200 ( params : MessageActionsParams ) => {
185201 if ( ! chatClient ) {
@@ -190,9 +206,10 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
190206 chatClient,
191207 t,
192208 colors,
209+ handleMessageInfo,
193210 } ) ;
194211 } ,
195- [ chatClient , colors , t ] ,
212+ [ chatClient , colors , t , handleMessageInfo ] ,
196213 ) ;
197214
198215 if ( ! channel || ! chatClient ) {
@@ -232,6 +249,7 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
232249 ) }
233250 < AITypingIndicatorView channel = { channel } />
234251 < MessageInput />
252+ < MessageInfoBottomSheet message = { selectedMessage } ref = { messageInfoBottomSheetRef } />
235253 </ Channel >
236254 </ View >
237255 ) ;
0 commit comments