Skip to content
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

[HOLD PR #49539][$250] Search-Different navigation when closing report via app back button and device back navigation #51192

Open
2 of 8 tasks
lanitochka17 opened this issue Oct 21, 2024 · 39 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 21, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.51-2
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
**If this was caught during regression testing, add the test name, ID and link from TestRail:**N/A
Email or phone of affected tester (no customers): applausetester+kh081006@applause.expensifail.com
Issue reported by: Applause - Internal Team

Action Performed:

  1. Launch ND (hybrid or standalone)
  2. Go to Account settings
  3. Tap Workspaces
  4. Tap on the search icon on the top right
  5. Open any report
  6. Tap on the app back button twice
  7. Note that app returns to Account settings
  8. Go back to Workspaces and tap search icon
  9. Open any report
  10. Swipe to the right twice using device navigation (swipe on iOS, back or swipe on Android)

Expected Result:

App will return to Account settings when the report is opened in Workspaces and swiped to the right twice

Actual Result:

App will return to LHN when the report is opened in Workspaces and swiped to the right twice.
When performing similar steps using app back button, it returns to Account settings (Step 7)

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Bug6641270_1729532054815.ScreenRecording_10-22-2024_01-27-58_1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021851013558310537161
  • Upwork Job ID: 1851013558310537161
  • Last Price Increase: 2024-12-09
Issue OwnerCurrent Issue Owner: @ntdiary
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 21, 2024
Copy link

melvin-bot bot commented Oct 21, 2024

Triggered auto assignment to @strepanier03 (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@lanitochka17
Copy link
Author

@strepanier03 FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@huult
Copy link
Contributor

huult commented Oct 22, 2024

Edited by proposal-police: This proposal was edited at 2024-10-22 18:02:29 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

Different navigation when closing report via app back button and device back navigation

What is the root cause of that problem?

When navigating back from a chat opened in the Chats section—either by swiping (iOS) or using the back button (Android)—the topmost screen of the BOTTOM_TAB_NAVIGATOR is HOME. This occurs because when we swipe, the navigation stack goes back through the screens in the following order: Report → Setting Workspace → BOTTOM_TAB_NAVIGATOR, resulting in the topmost screen in the BOTTOM_TAB_NAVIGATOR being Home. Therefore, when we swipe, we are taken to the Home page. Here is the log for this issue using const state = navigationRef.current?.getRootState() as State<RootStackParamList>;

  • Screenshot 2024-10-23 at 01 18 08

This issue does not occur when using the back button, as we use pop for navigation in that case

Navigation.goBack(undefined, false, true);

// If the central pane is defined after the pop action, we need to check if it's synced with the bottom tab screen.
// If not, we need to pop to the bottom tab screen/screens to sync it with the new central pane.
if (topmostCentralPaneRouteAfterPop && topmostBottomTabRoute?.name !== matchingBottomTabRoute.name) {
const bottomTabNavigator = rootState.routes.find((item: NavigationStateRoute) => item.name === NAVIGATORS.BOTTOM_TAB_NAVIGATOR)?.state;
if (bottomTabNavigator && bottomTabNavigator.index) {
const matchingIndex = bottomTabNavigator.routes.findLastIndex((item) => item.name === matchingBottomTabRoute.name);
const indexToPop = matchingIndex !== -1 ? bottomTabNavigator.index - matchingIndex : undefined;
navigationRef.current.dispatch({...StackActions.pop(indexToPop), target: bottomTabNavigator?.key});
}
}
}

What changes do you think we should make in order to solve the problem?

This issue using solution same with PR 48990

When navigating back from a chat opened in the Chats section to a chat opened in the Search section, we need to update the condition to pop Home from the Bottom Tab Navigator when the case of Report → Setting Workspace → BOTTOM_TAB_NAVIGATOR has Home as the topmost screen, ensuring the same behavior as when using the back button. Something like this:

//.src/libs/Navigation/AppNavigator/beforeRemoveReportOpenedFromSearchRHP/index.native.ts#L25

        function beforeRemoveReportOpenedFromSearchRHP(event: EventArg<'beforeRemove', true>) {
        ...
-        const shouldPopHome =
-                state.routes?.length >= 3 &&
-                state.routes.at(-1)?.name === SCREENS.REPORT &&
-                state.routes.at(-2)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR &&
-                state.routes.at(-3)?.name === SCREENS.SEARCH.CENTRAL_PANE &&
-                getTopmostBottomTabRoute(state)?.name === SCREENS.HOME;
+        const shouldPopHome =
+                (state.routes?.length >= 3 &&
+                state.routes.at(-1)?.name === SCREENS.REPORT &&
+                state.routes.at(-2)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR &&
+                state.routes.at(-3)?.name === SCREENS.SEARCH.CENTRAL_PANE &&
+                getTopmostBottomTabRoute(state)?.name === SCREENS.HOME) ||
+                (state.routes?.length >= 3 &&
+                state.routes.at(-1)?.name === SCREENS.REPORT &&
+                state.routes.at(-2)?.name === SCREENS.SETTINGS.WORKSPACES &&
+                state.routes.at(-3)?.name === NAVIGATORS.BOTTOM_TAB_NAVIGATOR &&
+                getTopmostBottomTabRoute(state)?.name === SCREENS.HOME);

        ...
        }

What alternative solutions did you explore? (Optional)

For the general case, not a specific one, we don't need to check state.routes.at(-2)?.name so that other cases can use:

//.src/libs/Navigation/AppNavigator/beforeRemoveReportOpenedFromSearchRHP/index.native.ts#L25

        function beforeRemoveReportOpenedFromSearchRHP(event: EventArg<'beforeRemove', true>) {
        ...
-        const shouldPopHome =
-                state.routes?.length >= 3 &&
-                state.routes.at(-1)?.name === SCREENS.REPORT &&
-                state.routes.at(-2)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR &&
-                state.routes.at(-3)?.name === SCREENS.SEARCH.CENTRAL_PANE &&
-                getTopmostBottomTabRoute(state)?.name === SCREENS.HOME;
+        const shouldPopHome =
+                (state.routes?.length >= 3 &&
+                state.routes.at(-1)?.name === SCREENS.REPORT &&
+                state.routes.at(-2)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR &&
+                state.routes.at(-3)?.name === SCREENS.SEARCH.CENTRAL_PANE &&
+                getTopmostBottomTabRoute(state)?.name === SCREENS.HOME) ||
+                (state.routes?.length >= 3 &&
+                state.routes.at(-1)?.name === SCREENS.REPORT &&
+                state.routes.at(-3)?.name === NAVIGATORS.BOTTOM_TAB_NAVIGATOR &&
+                getTopmostBottomTabRoute(state)?.name === SCREENS.HOME);

        ...
        }

Here is test branch

POC
Screen.Recording.2024-10-23.at.00.41.39.mov

@c3024
Copy link
Contributor

c3024 commented Oct 23, 2024

Edited by proposal-police: This proposal was edited at 2024-10-23 09:49:34 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

Back button/gesture behaviour does not match with on screen back button press behaviour on native apps.

What is the root cause of that problem?

When we go to the workspaces list page, we have "Home" and "Settings Root" in BottomTabNavigator. When we open a report from there, we push another "Home" route to the BottomTabNavigator because the Report screen is a center pane and target screen is different.

if (isCentralPaneName(action.payload.name) && (isTargetScreenDifferentThanCurrent || areParamsDifferent)) {
// We need to push a tab if the tab doesn't match the central pane route that we are going to push.
const topmostBottomTabRoute = getTopmostBottomTabRoute(rootState);
const focusedRoute = findFocusedRoute(stateFromPath);
const policyIDFromQuery = extractPolicyIDFromQuery(focusedRoute);
const matchingBottomTabRoute = getMatchingBottomTabRouteForState(stateFromPath, policyID ?? policyIDFromQuery);
const isOpeningSearch = matchingBottomTabRoute.name === SCREENS.SEARCH.BOTTOM_TAB;
const isNewPolicyID =
((topmostBottomTabRoute?.params as Record<string, string | undefined>)?.policyID ?? '') !==
((matchingBottomTabRoute?.params as Record<string, string | undefined>)?.policyID ?? '');
if (topmostBottomTabRoute && (topmostBottomTabRoute.name !== matchingBottomTabRoute.name || isNewPolicyID || isOpeningSearch)) {
root.dispatch({
type: CONST.NAVIGATION.ACTION_TYPE.PUSH,
payload: matchingBottomTabRoute,
});
}

When, we go back with back gesture/button on native apps, the routes are popped from the state. So, once the "Report" and "Settings Workspace" screens are popped, the "Home" screen is next. So, LHN shows up.

But, when click on screen back button when on "Settings Workspace", we readjust the state popping the recently added "Home" screen above from the "BottomTabNavigator" to reach to "Settings Root", so it navigates to Settings page.

// If the central pane is defined after the pop action, we need to check if it's synced with the bottom tab screen.
// If not, we need to pop to the bottom tab screen/screens to sync it with the new central pane.

What changes do you think we should make in order to solve the problem?

Earlier, we can open a report in "central pane" on narrow layouts only from Home or Report screens because reports could be accessed only from LHN or from FAB or from a report. In all these cases, the BottomTabNavigator topMostRoute was always Home. So, this condition never executed when the screen navigated to is a report

if (topmostBottomTabRoute && (topmostBottomTabRoute.name !== matchingBottomTabRoute.name || isNewPolicyID || isOpeningSearch)) {

so, the push action of another Home never happened.

But, now, we can open report from other screens such as the workspace list page thanks to Search Router. Since, we can open report from any such screen, we would only want the report screen to be added to the state. We do not want to push another "Home" into BottomTabNavigator in these cases on narrow layouts because when we pop the last route before reaching BottomTabNavigator, we expect to navigate to the the bottom tab corresponding to this last route popped.
We need pushing this "Home" only on normal screens and not on narrow screens. So, we can change this

root.dispatch({

to

const bottomTabNavigatorRoute = rootState?.routes.findLast((route) => route.name === NAVIGATORS.BOTTOM_TAB_NAVIGATOR);
const homeExistsInBottomTab = bottomTabNavigatorRoute?.state?.routes.find((route) => route.name === SCREENS.HOME);
if (!(isNarrowLayout && homeExistsInBottomTab)) {
                root.dispatch({

I think there is always "Home" in bottom tab even when begin from a deeplink, so we can omit the homeExistsInBottomTab check. Since, this happens with the new Search Router we can also add this check only if bottom tab route is "Home" like

if (!(.... && matchingBottomTabRoute === SCREENS.HOME)

What alternative solutions did you explore? (Optional)

@melvin-bot melvin-bot bot added the Overdue label Oct 23, 2024
Copy link

melvin-bot bot commented Oct 24, 2024

@strepanier03 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

Copy link

melvin-bot bot commented Oct 28, 2024

@strepanier03 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@strepanier03
Copy link
Contributor

Got this tested and repro just fine. Looking at project and priority now.

@melvin-bot melvin-bot bot removed the Overdue label Oct 28, 2024
@strepanier03 strepanier03 added the External Added to denote the issue can be worked on by a contributor label Oct 28, 2024
Copy link

melvin-bot bot commented Oct 28, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021851013558310537161

@melvin-bot melvin-bot bot changed the title Search-Different navigation when closing report via app back button and device back navigation [$250] Search-Different navigation when closing report via app back button and device back navigation Oct 28, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 28, 2024
Copy link

melvin-bot bot commented Oct 28, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @ntdiary (External)

@ntdiary
Copy link
Contributor

ntdiary commented Oct 29, 2024

test.mp4

@c3024 if we didn't push the Home, the LHN will not display correctly once we stretch the browser. 😂

As for @huult's proposal, I need more time to test some cases, will update tomorrow. :)

@c3024
Copy link
Contributor

c3024 commented Oct 29, 2024

Oh, I missed considering that. 😃

We can consider restricting this only to native apps like this

if (!(matchingBottomTabRoute === SCREENS.HOME && [CONST.PLATFORM.IOS, CONST.PLATFORM.ANDROID].includes(getPlatform()))

Since clicking on browser back button adjusts state based on path, it adds suitable BottomTabNavigator to the state and this is not an issue for browsers. The OP also says that this bug exists only on native apps.

@ntdiary
Copy link
Contributor

ntdiary commented Oct 30, 2024

Regarding @huult 's proposal, while it can address this issue, Search can actually be opened from many pages, so I would prefer to wait for a more universal solution. :)

test.mp4

@huult
Copy link
Contributor

huult commented Oct 30, 2024

Proposal updated

  • Update with alternative solutions

@ntdiary Could you check it again? I removed thestate.routes.at(-2)?.name === SCREENS.SETTINGS.WORKSPACES condition so that other different settings pages can work. Thanks!

@ntdiary
Copy link
Contributor

ntdiary commented Oct 31, 2024

@ntdiary Could you check it again? I removed thestate.routes.at(-2)?.name === SCREENS.SETTINGS.WORKSPACES condition so that other different settings pages can work. Thanks!

@huult, seems to work well, will continue to test some prev cases to prevent regressions. :)

Copy link

melvin-bot bot commented Nov 4, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Nov 4, 2024
@ntdiary
Copy link
Contributor

ntdiary commented Nov 4, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

There isn't a perfect solution at the moment. I started a discussion in #49122, will provide an update in the next couple of days. Also, I'm still open to get a more perfect solution here. :)

@melvin-bot melvin-bot bot removed the Overdue label Nov 4, 2024
Copy link

melvin-bot bot commented Nov 18, 2024

@ntdiary @strepanier03 this issue is now 4 weeks old, please consider:

  • Finding a contributor to fix the bug
  • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

@melvin-bot melvin-bot bot added the Overdue label Nov 18, 2024
Copy link

melvin-bot bot commented Nov 18, 2024

@ntdiary, @strepanier03 Huh... This is 4 days overdue. Who can take care of this?

Copy link

melvin-bot bot commented Nov 18, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

Copy link

melvin-bot bot commented Nov 20, 2024

@ntdiary, @strepanier03 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

Copy link

melvin-bot bot commented Nov 22, 2024

@ntdiary, @strepanier03 Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

@ntdiary
Copy link
Contributor

ntdiary commented Nov 22, 2024

not overdue, waiting for navigation refactoring. :)

@melvin-bot melvin-bot bot removed the Overdue label Nov 22, 2024
Copy link

melvin-bot bot commented Nov 25, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Nov 25, 2024
Copy link

melvin-bot bot commented Nov 26, 2024

@ntdiary, @strepanier03 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@ntdiary
Copy link
Contributor

ntdiary commented Nov 26, 2024

the refactoring PR #49539 is still in progress, maybe we can set this issue to Weekly. :)

@melvin-bot melvin-bot bot removed the Overdue label Nov 26, 2024
@huult
Copy link
Contributor

huult commented Nov 26, 2024

If you don't want to wait, then let's go with my proposal.

Copy link

melvin-bot bot commented Dec 2, 2024

@ntdiary, @strepanier03 Eep! 4 days overdue now. Issues have feelings too...

@melvin-bot melvin-bot bot added the Overdue label Dec 2, 2024
Copy link

melvin-bot bot commented Dec 2, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

Copy link

melvin-bot bot commented Dec 4, 2024

@ntdiary, @strepanier03 Still overdue 6 days?! Let's take care of this!

@ntdiary
Copy link
Contributor

ntdiary commented Dec 5, 2024

Personally, I'm ok to hold this for navigation refactoring. :)

Copy link

melvin-bot bot commented Dec 9, 2024

@ntdiary, @strepanier03 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label Dec 9, 2024
Copy link

melvin-bot bot commented Dec 9, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@mallenexpensify mallenexpensify added Weekly KSv2 and removed Daily KSv2 labels Dec 9, 2024
@melvin-bot melvin-bot bot removed the Overdue label Dec 9, 2024
@mallenexpensify mallenexpensify changed the title [$250] Search-Different navigation when closing report via app back button and device back navigation [HOLD PR #49539][$250] Search-Different navigation when closing report via app back button and device back navigation Dec 9, 2024
@mallenexpensify mallenexpensify removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 9, 2024
@mallenexpensify
Copy link
Contributor

Put on hold pending PR #49539
This might be related or a dupe, it's also on hold, pending the same PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
Development

No branches or pull requests

6 participants