@@ -33,6 +33,7 @@ import { useStreamChatContext } from '../context/StreamChatContext.tsx';
3333import { CustomAttachmentPickerSelectionBar } from '../components/AttachmentPickerSelectionBar.tsx' ;
3434import { MessageInfoBottomSheet } from '../components/MessageInfoBottomSheet.tsx' ;
3535import { CustomAttachmentPickerContent } from '../components/AttachmentPickerContent.tsx' ;
36+ import { ThreadType } from 'stream-chat-react-native-core' ;
3637
3738export type ChannelScreenNavigationProp = NativeStackNavigationProp <
3839 StackNavigatorParamList ,
@@ -195,7 +196,29 @@ export const ChannelScreen: React.FC<ChannelScreenProps> = ({
195196 }
196197 setSelectedThread ( parentMessage ) ;
197198 setThread ( parentMessage ) ;
198- navigation . navigate ( 'ThreadScreen' , { channel, thread : parentMessage , targetedMessageId } ) ;
199+ const params : StackNavigatorParamList [ 'ThreadScreen' ] = {
200+ channel,
201+ targetedMessageId,
202+ thread : parentMessage ,
203+ } ;
204+ const hasThreadInStack = navigation . getState ( ) . routes . some ( ( route ) => {
205+ if ( route . name !== 'ThreadScreen' ) {
206+ return false ;
207+ }
208+ const routeParams = route . params as StackNavigatorParamList [ 'ThreadScreen' ] | undefined ;
209+ const routeThreadId =
210+ ( routeParams ?. thread as LocalMessage ) ?. id ??
211+ ( routeParams ?. thread as ThreadType ) ?. thread ?. id ;
212+ const routeChannelId = routeParams ?. channel ?. id ;
213+ return routeThreadId === parentMessage . id && routeChannelId === channel . id ;
214+ } ) ;
215+
216+ if ( hasThreadInStack ) {
217+ navigation . popTo ( 'ThreadScreen' , params ) ;
218+ return ;
219+ }
220+
221+ navigation . navigate ( 'ThreadScreen' , params ) ;
199222 } ,
200223 [ channel , navigation , setThread ] ,
201224 ) ;
0 commit comments