Skip to content

Commit

Permalink
Merge pull request #41258 from Expensify/jack-fixLinking
Browse files Browse the repository at this point in the history
[CP Staging] Re-add the missing changes in InitialURLContextProvider

(cherry picked from commit 1f8c028)
  • Loading branch information
thienlnam authored and OSBotify committed Apr 29, 2024
1 parent 0ad0243 commit 859ee94
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/InitialURLContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -14,7 +15,16 @@ type InitialURLContextProviderProps = {
};

function InitialURLContextProvider({children, url}: InitialURLContextProviderProps) {
return <InitialURLContext.Provider value={url}>{children}</InitialURLContext.Provider>;
const [initialURL, setInitialURL] = useState(url);
useEffect(() => {
if (initialURL) {
return;
}
Linking.getInitialURL().then((initURL) => {
setInitialURL(initURL as Route);
});
}, [initialURL]);
return <InitialURLContext.Provider value={initialURL}>{children}</InitialURLContext.Provider>;
}

InitialURLContextProvider.displayName = 'InitialURLContextProvider';
Expand Down

0 comments on commit 859ee94

Please sign in to comment.