Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Re-add the missing changes in InitialURLContextProvider #41258

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading