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

[Wave 8] [Ideal Nav] Save scroll position on HOME screen #38161

Merged

Conversation

adamgrzybowski
Copy link
Contributor

Details

Problem

There were two reasons why the scroll is reset when switching tabs / going back in history.

  • If we switch from HOME to SETTINGS tab, the HOME won't be displayed and the scroll is reset to 0.
  • We use stack for bottomTabNavigator to achieve desired pattern for browser history. That means if we go HOME -> SETTINGS -> HOME the screen on the top is actually a different component than the initial HOME screen.

Solution

To make sure the scroll position is persistent when we navigate between tabs there is a new ScrollOffsetContext used to save the value. When the user navigates to the HOME tab we check if there is a scroll offset saved for this particular screen with given policyID. If yes we can use it to set the offset.

Note

After some modifications this solution could be used to save the conversation scroll position if this is something we want to implement.

Solution I tried

In theory if we have situation where we navigate HOME -> SETTINGS -> HOME we could try to reuse the first HOME component to render the second HOME if both have the same policyID.

On the web for some reason after this operation the scroll position is lost anyway. Even if we force the HOME screen to stay displayed under other tabs.

On the mobile it completely breaks the screen rendering.

However, reusing screens may slightly improve performance when opening the HOME tab on the web. Perhaps this is something to investigate in the future.

Fixed Issues

$ #35602
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Verify that no errors appear in the JS console
  1. Open the app on the HOME screen (the chat list)
  2. Scroll it
  3. Change tab to SETTINGS
  4. Change tab to HOME
  5. See if the position of the scroll is where you left it

extra steps for platforms with go back possible

  1. Go back to SETTINGS
  2. Go back again to HOME
  3. See if the position of the scroll is where you left it

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
androidNative.mov
Android: mWeb Chrome
androidWeb.mov
iOS: Native
iosNative.mov
iOS: mWeb Safari
iosWeb.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov

@adamgrzybowski adamgrzybowski requested a review from a team as a code owner March 12, 2024 18:24
@melvin-bot melvin-bot bot requested review from situchan and removed request for a team March 12, 2024 18:25
Copy link

melvin-bot bot commented Mar 12, 2024

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Copy link
Contributor

@situchan situchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not missing anything, the entire solution is not necessary for native as they're never unmounted before logout, right?

@situchan
Copy link
Contributor

Why can't we prevent unmount LHN when switch to other pages?
If it's for performance, we already have Freeze for that.

@adamgrzybowski
Copy link
Contributor Author

@situchan Not sure about unmounting but there is still the second problem.

On native if we switch tabs like HOME -> SETTINGS -> HOME, then the visible home screen is a different component than the first one. That's because we use the stack navigator underneath even for the bottom tab.

That means the scroll position from the first visit wouldn't persist on the second visit to this tab

The video below shows how it currently works on the main. You can compare it with the ios native video included for this PR

@situchan Not sure about unmounting but there is still the second problem. On native if we switch tabs like HOME -> SETTINGS -> HOME, then the second home component is actually a different component from the

Screen.Recording.2024-03-13.at.15.57.10.mov

@situchan
Copy link
Contributor

On native if we switch tabs like HOME -> SETTINGS -> HOME, then the second home component is actually a different component

Is it impossible to fix this?

@adamgrzybowski
Copy link
Contributor Author

Why can't we prevent unmount LHN when switch to other pages?
If it's for performance, we already have Freeze for that.

  1. Because we use the stack that means there may be many screens in the state of the bottom tab. Currently to optimize that we keep only one or two top screens mounted. React freeze can help with rendering but the screens still would take memory.

  2. Even if we keep all components mounted there is still a problem with the display. The CSS display property is set to none for the screens that are not on the top of the stack. This causes the layout of the scroll to have dimensions 0x0 so the scroll is reset to 0 as well.

@situchan
Copy link
Contributor

ok so this is inevitable for web.
But still I think we can fix HOME -> SETTINGS -> HOME, then the second home component is actually a different component for native.

I might be wrong but should we also keep Settings tab (now Profile tab for ideal nav v2) scroll position for consistency?

@adamgrzybowski
Copy link
Contributor Author

Is it impossible to fix this?

When implementing the bottom tab navigator we decided to use a stack that pretends to be a tab navigator instead of a real bottom tab.

Our motivation was the fact that the history in the browser seemed to be broken for the tab navigator. Or at least doesn't support the pattern that we wanted to implement.

Additionally, the stack navigator is more flexible which allowed us to implement some features without unnecessary nested navigators (I think this may be no longer needed with ideal-nav-v2)

In theory, we could go back, try to fix the react-navigation bottom tab history upstream, and switch the current implementation of the bottom tab for the real bottom tab but personally I don't see any reason to do that.

I might be wrong but should we also keep Settings tab (now Profile tab for ideal nav v2) scroll position for consistency?

Agree with this one. I see that the v2 was merged yesterday. In that case I can modify this PR to cover the settings scroll

@situchan
Copy link
Contributor

I can modify this PR to cover the settings scroll

ok let me know when it's done

@adamgrzybowski
Copy link
Contributor Author

@situchan Done!

@situchan
Copy link
Contributor

Conflicts!

@adamgrzybowski
Copy link
Contributor Author

@situchan bump

@situchan
Copy link
Contributor

situchan commented Mar 15, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
android.mov
Android: mWeb Chrome
mchrome.mov
iOS: Native
ios.mov
iOS: mWeb Safari
msafari.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov

@adamgrzybowski
Copy link
Contributor Author

Hey, @situchan It looks like this PR is ok to merge. Do you know who to ask for that?

@situchan
Copy link
Contributor

I didn't approve yet. Will do shortly

@situchan
Copy link
Contributor

@adamgrzybowski please fix conflict

@adamgrzybowski
Copy link
Contributor Author

@situchan resolved

@mountiny
Copy link
Contributor

@situchan what is your eta on this one please?

@situchan
Copy link
Contributor

eod

@situchan
Copy link
Contributor

Should this be considered out of scope?

There's glitch when lots of data in LHN:

Screen.Recording.2024-03-21.at.7.51.27.AM.mov

@situchan
Copy link
Contributor

This is polish but when switch focus mode, I think it's better to reset scroll position to top

Screen.Recording.2024-03-21.at.7.56.08.AM.mov

Copy link
Contributor

@situchan situchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, considering above concerns are non blockers

@adamgrzybowski
Copy link
Contributor Author

There's glitch when lots of data in LHN:

I think I saw something like this even without this PR. Not sure if we can do something about it here.

This is polish but when switch focus mode, I think it's better to reset scroll position to top

This is very good point. Let me fix that

@adamgrzybowski
Copy link
Contributor Author

@situchan okay, changing priority should now reset saved scrolls for home

hayata-suenaga
hayata-suenaga previously approved these changes Mar 21, 2024
Copy link
Contributor

@hayata-suenaga hayata-suenaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢

@hayata-suenaga
Copy link
Contributor

@situchan okay, changing priority should now reset saved scrolls for home

@situchan do we need to confirm this?

@situchan
Copy link
Contributor

@situchan okay, changing priority should now reset saved scrolls for home

@situchan do we need to confirm this?

Doing that review shortly

const previousPriorityMode = useRef<PriorityMode>(priorityMode);

useEffect(() => {
if (previousPriorityMode.current === priorityMode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use usePrevious hook to compare with prev props value.

Btw, is this reasonable approach to reset scroll of HOME screen here? This is general context provider.
I thought of handling in LHNOptionsList.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like having this in one place rather than scattering it in different files makes it easier to understand. But I am open to hear different opinions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I am fine with current approach.

@situchan
Copy link
Contributor

Please merge main. Perf tests failing

@adamgrzybowski
Copy link
Contributor Author

@situchan done

@situchan
Copy link
Contributor

@adamgrzybowski it's not fixed yet

Screen.Recording.2024-03-22.at.6.54.58.PM.mov

@adamgrzybowski
Copy link
Contributor Author

@situchan okay now it should work for the case with two apps opened

@situchan
Copy link
Contributor

🟢

Copy link
Contributor

@hayata-suenaga hayata-suenaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants