Skip to content

Commit

Permalink
Merge pull request #53074 from software-mansion-labs/war-in/fix-deepl…
Browse files Browse the repository at this point in the history
…inks

[CP Staging] [HybridApp] Fix deeplinks when clicking on app icon

(cherry picked from commit 78e9141)

(CP triggered by mountiny)
  • Loading branch information
srikarparsi authored and OSBotify committed Nov 25, 2024
1 parent 68f639a commit effe00e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions src/components/InitialURLContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,17 +23,33 @@ const InitialURLContext = createContext<InitialUrlContextType>({

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<typeof CONST.HYBRID_APP>;

/** Children passed to the context provider */
children: ReactNode;
};

function InitialURLContextProvider({children, url}: InitialURLContextProviderProps) {
const [initialURL, setInitialURL] = useState<Route | undefined>();
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);
Expand Down

0 comments on commit effe00e

Please sign in to comment.