-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Navigation.isActiveRoute function updated to handle currentRoute logic #4382
Changes from all commits
7fb86db
b7658db
f26b5a0
e43b311
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import _ from 'underscore'; | ||
import React from 'react'; | ||
import {StackActions, DrawerActions} from '@react-navigation/native'; | ||
import {StackActions, DrawerActions, useLinkBuilder} from '@react-navigation/native'; | ||
import PropTypes from 'prop-types'; | ||
import Onyx from 'react-native-onyx'; | ||
import linkTo from './linkTo'; | ||
|
@@ -125,13 +125,21 @@ function dismissModal(shouldOpenDrawer = false) { | |
/** | ||
* Check whether the passed route is currently Active or not. | ||
* | ||
* Building path with useLinkBuilder since navigationRef.current.getCurrentRoute().path | ||
* is undefined in the first navigation. | ||
* | ||
* @param {String} routePath Path to check | ||
* @return {Boolean} is active | ||
*/ | ||
function isActive(routePath) { | ||
function isActiveRoute(routePath) { | ||
const buildLink = useLinkBuilder(); | ||
|
||
// We remove First forward slash from the URL before matching | ||
const path = navigationRef.current && navigationRef.current.getCurrentRoute().path | ||
? navigationRef.current.getCurrentRoute().path.substring(1) | ||
const path = navigationRef.current && navigationRef.current.getCurrentRoute().name | ||
? buildLink( | ||
navigationRef.current.getCurrentRoute().name, | ||
navigationRef.current.getCurrentRoute().params, | ||
).substring(1) | ||
Comment on lines
-133
to
+142
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. We should have kept using |
||
: ''; | ||
return path === routePath; | ||
} | ||
|
@@ -167,7 +175,7 @@ DismissModal.defaultProps = { | |
export default { | ||
navigate, | ||
dismissModal, | ||
isActive, | ||
isActiveRoute, | ||
goBack, | ||
DismissModal, | ||
closeDrawer, | ||
|
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.
Apart from https://reactjs.org/docs/hooks-rules.html#only-call-hooks-from-react-functions. All good.
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.
Okay. But it seems that using
getPathFromState
will have to also be inside a component only. Any suggestions on this?React Navigation suggests this approach:
https://reactnavigation.org/docs/screen-tracking/#example
The second approach would then be creating a ref in
Navigation
export const currentRouteRef = React.createRef();
and in NavigationRoot.parseAndStoreRoute
currentRouteRef.current = path;
and this quite similar to fetch URL from Onyx
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.
It is already using navigationRef in the isActiveRoute. but NAB.