-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Android - Deeplink navigation does not work for RHN links. #28278
Changes from 3 commits
51f9f74
e9330ea
098bb11
958b028
44be36d
f2d683f
6d499eb
101790b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,51 @@ function setIsNavigationReady() { | |
resolveNavigationIsReadyPromise(); | ||
} | ||
|
||
function navContainsConcierge(state) { | ||
if (!state || !state.routeNames || !_.isArray(state.routeNames)) { | ||
return false; | ||
} | ||
|
||
return _.includes(state.routeNames, SCREENS.CONCIERGE); | ||
} | ||
|
||
/** | ||
* Waits for the navigation state to contain protected routes (specifically 'Concierge'). | ||
* If the navigation is in a state, where protected routes are available, the promise will resolve immediately. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure I understand, is "protected route" a new concept we're introducing? I'm not sure I understand what it has to do with Concierge specifically. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, it's just the way routes hidden behind the auth process are called. Since Concierge is the one of the most important screens that is available to users after logging in, I'm using it to detect the change and readiness of the navigation state. In simple words - when Concierge is present as one of the available routes in the nav state, this means that app is showing protected routes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there another way we can wait for navigation to finish? I'm not sure I like the idea of checking if Concierge is an available route before allowing navigation. There might be situations in the future where the Concierge route is not available (I.e anonymous accounts) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, though with current nav setup it's hard to come up with a better way. If the navigation was done using protected route guard components, that would be easier (or even unnecessary), but there's a conditional nav tree rendering in |
||
* | ||
* @function | ||
* @returns {Promise<void>} A promise that resolves to `true` when the Concierge route is present. | ||
* Rejects with an error if the navigation is not ready. | ||
* | ||
* @example | ||
* waitForProtectedRoutes() | ||
* .then(() => console.log('Protected routes are present!')) | ||
* .catch(error => console.error(error.message)); | ||
*/ | ||
function waitForProtectedRoutes() { | ||
return new Promise((resolve, reject) => { | ||
const isReady = navigationRef.current && navigationRef.current.isReady(); | ||
if (!isReady) { | ||
reject(new Error('[Navigation] is not ready yet!')); | ||
return; | ||
} | ||
const currentState = navigationRef.current.getState(); | ||
if (navContainsConcierge(currentState)) { | ||
resolve(); | ||
return; | ||
} | ||
let unsubscribe; | ||
const handleStateChange = ({data}) => { | ||
const state = lodashGet(data, 'state'); | ||
if (navContainsConcierge(state)) { | ||
unsubscribe(); | ||
resolve(); | ||
} | ||
}; | ||
unsubscribe = navigationRef.current.addListener('state', handleStateChange); | ||
}); | ||
} | ||
|
||
export default { | ||
setShouldPopAllStateOnUP, | ||
canNavigate, | ||
|
@@ -272,6 +317,7 @@ export default { | |
setIsNavigationReady, | ||
getTopmostReportId, | ||
getRouteNameFromStateEvent, | ||
waitForProtectedRoutes, | ||
getTopmostReportActionId, | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments need to be updated now