From effe00ebb078ec7a7fab42d77bad817a70ef2bf3 Mon Sep 17 00:00:00 2001 From: Srikar Parsi <48188732+srikarparsi@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:56:36 -0500 Subject: [PATCH] Merge pull request #53074 from software-mansion-labs/war-in/fix-deeplinks [CP Staging] [HybridApp] Fix deeplinks when clicking on app icon (cherry picked from commit 78e9141a48e080e0d0a6cff17119e92bc82cc238) (CP triggered by mountiny) --- src/CONST.ts | 4 ++++ src/components/InitialURLContextProvider.tsx | 24 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 43ab23bc6fe7..dc311839c687 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -6350,6 +6350,10 @@ const CONST = { PAID_ADOPTION: 'paid_adoption', }, }, + + HYBRID_APP: { + REORDERING_REACT_NATIVE_ACTIVITY_TO_FRONT: 'reorderingReactNativeActivityToFront', + }, } as const; type Country = keyof typeof CONST.ALL_COUNTRIES; diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx index adf361a2573d..c84379af36d8 100644 --- a/src/components/InitialURLContextProvider.tsx +++ b/src/components/InitialURLContextProvider.tsx @@ -1,8 +1,12 @@ import React, {createContext, useEffect, useMemo, useState} from 'react'; import type {ReactNode} from 'react'; import {Linking} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; import {signInAfterTransitionFromOldDot} from '@libs/actions/Session'; +import Navigation from '@navigation/Navigation'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import {useSplashScreenStateContext} from '@src/SplashScreenStateContext'; @@ -19,7 +23,7 @@ const InitialURLContext = createContext({ type InitialURLContextProviderProps = { /** URL passed to our top-level React Native component by HybridApp. Will always be undefined in "pure" NewDot builds. */ - url?: Route; + url?: Route | ValueOf; /** Children passed to the context provider */ children: ReactNode; @@ -27,9 +31,25 @@ type InitialURLContextProviderProps = { function InitialURLContextProvider({children, url}: InitialURLContextProviderProps) { const [initialURL, setInitialURL] = useState(); - const {setSplashScreenState} = useSplashScreenStateContext(); + const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); + const {splashScreenState, setSplashScreenState} = useSplashScreenStateContext(); useEffect(() => { + if (url !== CONST.HYBRID_APP.REORDERING_REACT_NATIVE_ACTIVITY_TO_FRONT) { + return; + } + + if (splashScreenState !== CONST.BOOT_SPLASH_STATE.HIDDEN) { + setSplashScreenState(CONST.BOOT_SPLASH_STATE.READY_TO_BE_HIDDEN); + Navigation.navigate(lastVisitedPath as Route); + } + }, [lastVisitedPath, setSplashScreenState, splashScreenState, url]); + + useEffect(() => { + if (url === CONST.HYBRID_APP.REORDERING_REACT_NATIVE_ACTIVITY_TO_FRONT) { + return; + } + if (url) { signInAfterTransitionFromOldDot(url).then((route) => { setInitialURL(route);