11import { NavigationContainer } from '@react-navigation/native' ;
22import React from 'react' ;
3- import { SafeAreaView , StatusBar , Text , View } from 'react-native' ;
3+ import { Linking , SafeAreaView , StatusBar , Text , View } from 'react-native' ;
44import { navigationRef } from './Navigation/rootNavigation' ;
55import StackNavigationPage from './Navigation/stackNavigation' ;
66import ApplicationColors from './config/appColors' ;
77import {
88 ARCHIVED_SCREEN ,
9+ CONVERSATION_SCREEN ,
910 CONVERSATION_STACK ,
1011 COUNTRY_LIST_SCREEN ,
1112 PROFILE_SCREEN ,
@@ -23,7 +24,11 @@ const linking = {
2324 screens : {
2425 [ REGISTERSCREEN ] : REGISTERSCREEN ,
2526 [ PROFILE_SCREEN ] : PROFILE_SCREEN ,
26- [ CONVERSATION_STACK ] : CONVERSATION_STACK ,
27+ [ CONVERSATION_STACK ] : {
28+ screens : {
29+ [ CONVERSATION_SCREEN ] : CONVERSATION_SCREEN , // This should match the path used in the deep link
30+ } ,
31+ } ,
2732 [ RECENTCHATSCREEN ] : RECENTCHATSCREEN ,
2833 [ COUNTRY_LIST_SCREEN ] : COUNTRY_LIST_SCREEN ,
2934 [ USERS_LIST_SCREEN ] : USERS_LIST_SCREEN ,
@@ -34,6 +39,42 @@ const linking = {
3439} ;
3540
3641export function MirrorflyChatComponent ( ) {
42+ React . useEffect ( ( ) => {
43+ const handleDeepLink = ( { url } ) => {
44+ if ( url ) {
45+ const route = url . replace ( getAppSchema ( ) , '' ) ;
46+ const queryString = route . split ( '?' ) [ 1 ] ;
47+ // Manually parse the query string
48+ const params = { } ;
49+ if ( queryString ) {
50+ queryString . split ( '&' ) . forEach ( param => {
51+ const [ key , value ] = param . split ( '=' ) ;
52+ params [ key ] = decodeURIComponent ( value ) ;
53+ } ) ;
54+ }
55+ const { jid } = params ;
56+ setTimeout ( ( ) => {
57+ navigationRef . current ?. navigate ( CONVERSATION_STACK , {
58+ screen : CONVERSATION_SCREEN ,
59+ params : { jid } ,
60+ } ) ;
61+ } , 10 ) ;
62+ }
63+ } ;
64+
65+ Linking . getInitialURL ( ) . then ( url => {
66+ if ( url ) {
67+ handleDeepLink ( { url } ) ;
68+ }
69+ } ) ;
70+
71+ const linkingListener = Linking . addEventListener ( 'url' , handleDeepLink ) ;
72+
73+ return ( ) => {
74+ linkingListener . remove ( ) ;
75+ } ;
76+ } , [ ] ) ;
77+
3778 if ( ! getAppInitStatus ( ) ) {
3879 return (
3980 < SafeAreaView style = { { flex : 1 , backgroundColor : ApplicationColors . headerBg } } >
0 commit comments