-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add beforeRemoveReportOpenedFromSearchRHP
- Loading branch information
1 parent
86742b3
commit 83ccc2e
Showing
4 changed files
with
55 additions
and
24 deletions.
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
41 changes: 41 additions & 0 deletions
41
src/libs/Navigation/AppNavigator/beforeRemoveReportOpenedFromSearchRHP/index.native.ts
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {StackActions} from '@react-navigation/native'; | ||
import type {EventArg} from '@react-navigation/native'; | ||
import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import navigationRef from '@libs/Navigation/navigationRef'; | ||
import type {RootStackParamList, State} from '@libs/Navigation/types'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
/** | ||
* When we go back from the chat opened in the Chats section to the chat opened in the Search RHP we have to pop the Home screen from the Bottom tab navigator to display correctly Search page under RHP on native platform. | ||
* It fixes this issue: https://github.com/Expensify/App/issues/48882 | ||
*/ | ||
function beforeRemoveReportOpenedFromSearchRHP(event: EventArg<'beforeRemove', true>) { | ||
if (!navigationRef.current) { | ||
return; | ||
} | ||
|
||
const state = navigationRef.current?.getRootState() as State<RootStackParamList>; | ||
|
||
if (!state) { | ||
return; | ||
} | ||
|
||
const shouldPopHome = | ||
state.routes?.length >= 3 && | ||
state.routes.at(-1)?.name === SCREENS.REPORT && | ||
state.routes.at(-2)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR && | ||
getTopmostBottomTabRoute(state)?.name === SCREENS.HOME; | ||
|
||
if (!shouldPopHome) { | ||
return; | ||
} | ||
|
||
event.preventDefault(); | ||
const bottomTabState = state?.routes?.at(0)?.state; | ||
navigationRef.dispatch({...StackActions.pop(), target: bottomTabState?.key}); | ||
Navigation.goBack(); | ||
} | ||
|
||
export default beforeRemoveReportOpenedFromSearchRHP; |
4 changes: 4 additions & 0 deletions
4
src/libs/Navigation/AppNavigator/beforeRemoveReportOpenedFromSearchRHP/index.ts
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** The issue fixed by this handler is related to navigating back on native platforms. For more information, see the index.native.ts file in this folder */ | ||
function beforeRemoveReportOpenedFromSearchRHP() {} | ||
|
||
export default beforeRemoveReportOpenedFromSearchRHP; |
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