From 859ee945cb2ca1b54927c87b8625a3f7b06eb1ea Mon Sep 17 00:00:00 2001
From: Jack Nam <30609178+thienlnam@users.noreply.github.com>
Date: Mon, 29 Apr 2024 15:35:54 -0700
Subject: [PATCH] Merge pull request #41258 from Expensify/jack-fixLinking
[CP Staging] Re-add the missing changes in InitialURLContextProvider
(cherry picked from commit 1f8c0286bb5b3d47b7f2dd0fc653417d249c7fa7)
---
src/components/InitialURLContextProvider.tsx | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/components/InitialURLContextProvider.tsx b/src/components/InitialURLContextProvider.tsx
index 710f045ede4e..a3df93844ca9 100644
--- a/src/components/InitialURLContextProvider.tsx
+++ b/src/components/InitialURLContextProvider.tsx
@@ -1,5 +1,6 @@
-import React, {createContext} from 'react';
+import React, {createContext, useEffect, useState} from 'react';
import type {ReactNode} from 'react';
+import {Linking} from 'react-native';
import type {Route} from '@src/ROUTES';
/** Initial url that will be opened when NewDot is embedded into Hybrid App. */
@@ -14,7 +15,16 @@ type InitialURLContextProviderProps = {
};
function InitialURLContextProvider({children, url}: InitialURLContextProviderProps) {
- return {children};
+ const [initialURL, setInitialURL] = useState(url);
+ useEffect(() => {
+ if (initialURL) {
+ return;
+ }
+ Linking.getInitialURL().then((initURL) => {
+ setInitialURL(initURL as Route);
+ });
+ }, [initialURL]);
+ return {children};
}
InitialURLContextProvider.displayName = 'InitialURLContextProvider';