Skip to content

Instantly share code, notes, and snippets.

@kaushal9678
Created April 2, 2021 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaushal9678/43e27c489884a2596201d7874c0269af to your computer and use it in GitHub Desktop.
Save kaushal9678/43e27c489884a2596201d7874c0269af to your computer and use it in GitHub Desktop.
for terminated app
useEffect(() => {
AppState.addEventListener("change", _handleAppStateChange);
Linking.getInitialURL().then((url) => {
if (url) {
const route = url.replace(/.*?:\/\//g, '').split('?');
//if app is open first time and deep link path is initial route
if(url.includes('/jobs-') && appState.current === "active"){
const job = route[0].substring(route[0].lastIndexOf('/') + 1)
const jobSearch = job.split('-').join(" ")
searchScreenViewModel.keyword = jobSearch;
performSearch(jobSearch,false);
}else{//redirect user to particular page
manageRoutes(url);
}
}
}).catch(err => console.error('An error occurred', err));
return () => {
AppState.removeEventListener("change", _handleAppStateChange);
};
}, [])
useEffect(() => {
//used if app is in background and deeplink path is initial route name
GlobalEmitter.on(GlobalEvents.JOB_SEARCH_DEEP_LINK,deepLinkCall);
return () => {
GlobalEmitter.removeListener(GlobalEvents.JOB_SEARCH_DEEP_LINK, deepLinkCall);
};
}, []);
const deepLinkCall=(keyword:string)=>{
searchScreenViewModel.keyword = keyword;
setJobTitleText(keyword);
if(currentRoute !== "Search"){
navigation.navigateBackToScreen(NavigationScreens.Search)
}
performSearch(keyword,false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment