-
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
Improve goBack function #26498
Merged
mountiny
merged 16 commits into
Expensify:main
from
adamgrzybowski:@swm/improve-goBack-with-fallback-route
Nov 13, 2023
Merged
Improve goBack function #26498
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f747ae9
improve goBack function
adamgrzybowski 0644669
Merge branch 'main' into @swm/improve-goBack-with-fallback-route
adamgrzybowski 881dc84
fix typo
adamgrzybowski 3fb6f8e
Merge branch 'main' into @swm/improve-goBack-with-fallback-route
adamgrzybowski 59c3cdc
fix tests
adamgrzybowski d672079
Merge branch 'main' into @swm/improve-goBack-with-fallback-route
adamgrzybowski 5fd8ec9
limit search for path to 5 screens from the top
adamgrzybowski 6d90b44
Merge branch 'main' into @swm/improve-goBack-with-fallback-route
WojtekBoman fac03c4
Add OptionRowLHNDataReport
WojtekBoman 201ea6d
Merge branch 'main' into @swm/improve-goBack-with-fallback-route
WojtekBoman 22114be
Fix propTypes in OptionRowLHNData
WojtekBoman 35b4e44
Fix flatList position after deleting money requests
WojtekBoman e1ca40f
Merge branch 'main' into @swm/improve-goBack-with-fallback-route
WojtekBoman f1ba1c7
Merge branch 'main' into @swm/improve-goBack-with-fallback-route
WojtekBoman aec50d8
Remove the useFocusEffect hook from ReportActionsList
WojtekBoman 057f055
Add AUTOSCROLL_TO_TOP_THRESHOLD const
WojtekBoman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import _ from 'lodash'; | ||
import lodashGet from 'lodash/get'; | ||
import {CommonActions, getPathFromState, StackActions} from '@react-navigation/native'; | ||
import {getActionFromState} from '@react-navigation/core'; | ||
import {getActionFromState, findFocusedRoute} from '@react-navigation/core'; | ||
import Log from '../Log'; | ||
import DomUtils from '../DomUtils'; | ||
import linkTo from './linkTo'; | ||
|
@@ -70,6 +70,24 @@ const getActiveRouteIndex = function (route, index) { | |
return index; | ||
}; | ||
|
||
function getPathsForRoutesInRootNavigator() { | ||
let currentState = navigationRef.getRootState(); | ||
const paths = []; | ||
|
||
while (currentState.routes.length > 0) { | ||
try { | ||
const path = getPathFromState(currentState, linkingConfig.config); | ||
if (path) { | ||
paths.push(path.substring(1)); | ||
} | ||
} catch (e) { | ||
return paths; | ||
} | ||
currentState = {...currentState, routes: currentState.routes.slice(0, -1), index: currentState.index - 1}; | ||
} | ||
return paths; | ||
} | ||
|
||
/** | ||
* Main navigation method for redirecting to a route. | ||
* @param {String} route | ||
|
@@ -116,7 +134,6 @@ function goBack(fallbackRoute, shouldEnforceFallback = false, shouldPopToTop = f | |
} | ||
|
||
const isFirstRouteInNavigator = !getActiveRouteIndex(navigationRef.current.getState()); | ||
|
||
if (isFirstRouteInNavigator) { | ||
const rootState = navigationRef.getRootState(); | ||
const lastRoute = _.last(rootState.routes); | ||
|
@@ -132,6 +149,22 @@ function goBack(fallbackRoute, shouldEnforceFallback = false, shouldPopToTop = f | |
return; | ||
} | ||
|
||
const isCentralPaneFocused = findFocusedRoute(navigationRef.current.getState()).name === NAVIGATORS.CENTRAL_PANE_NAVIGATOR; | ||
const pathsForRoutesInRootNavigator = getPathsForRoutesInRootNavigator(); | ||
|
||
// Allow CentralPane to use goBack with fallback route. | ||
if (isCentralPaneFocused && fallbackRoute && !pathsForRoutesInRootNavigator.includes(fallbackRoute)) { | ||
navigate(fallbackRoute, CONST.NAVIGATION.TYPE.FORCED_UP); | ||
return; | ||
} | ||
|
||
// Add posibility to go back more than one screen in root navigator. | ||
if (isCentralPaneFocused && fallbackRoute && pathsForRoutesInRootNavigator.indexOf(fallbackRoute) > 0) { | ||
const popNumber = pathsForRoutesInRootNavigator.indexOf(fallbackRoute); | ||
navigationRef.current.dispatch(StackActions.pop(popNumber)); | ||
return; | ||
} | ||
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. NAB. Define the |
||
|
||
navigationRef.current.goBack(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this may cause a performance degradation for users who keep using the app for long periods. The more you use the app the more paths we have to extract. Most of the paths we get will be a waste. I suggest to implement an early return mechanism.
The 5 limit is used as a threshold. There would be no case where we would pop more than 4 screens. Currently I think the max to pop is 2. So maybe drop the 5 to 3.