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

Scroll To Last Index After Layout Change Of List #15662

Closed
wants to merge 10 commits into from
Closed

Scroll To Last Index After Layout Change Of List #15662

wants to merge 10 commits into from

Conversation

Litande
Copy link

@Litande Litande commented Mar 4, 2023

Details

Added layoutChange function that will scroll to last index and fix position in case the original scroll happened before layout changed.

Fixed Issues

$ 15303
PROPOSAL: 15303(COMMENT)

Tests

Note: this behavior is only related to IOS and impacts native behavior.

  1. Go to any chat
  2. Write a few messages at least enough to have scroll
  3. Write a multi line messages make it even five six rows
  4. Scroll in such a way up so you will see only half of the message near the button.
  5. Make sure on simulator keyboard is enabled
  6. Long press the long message and select edit
  7. Verify the edit view and actions are visible and not covered by keyboard
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Verify that no errors appear in the JS console

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 / Chrome
    • iOS / native
    • iOS / 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 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 correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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 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(themeColors.componentBG)
  • 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 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 author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
New.Expensify.-.8.March.2023.mp4
Mobile Web - Chrome
Android.Studio.-.Emulator.-.8.March.2023.mp4
Mobile Web - Safari
Simulator.-.iPhone.14.Pro.-.8.March.2023.mp4
Desktop
Electron.-.New.Expensify.-.8.March.2023.mp4
iOS
Simulator.-.iPhone.14.Pro.-.6.March.2023.mp4
Android
qemu-system-aarch64.-.Android.Emulator.-.Pixel_6_API_32_5554.-.6.March.2023.mp4

…t change from report actions list to handle index scroll adjustment after layout is changed
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Litande

This comment was marked as off-topic.

@Litande Litande marked this pull request as ready for review March 6, 2023 07:23
@Litande Litande requested a review from a team as a code owner March 6, 2023 07:23
@melvin-bot melvin-bot bot requested review from danieldoglas and removed request for a team March 6, 2023 07:24
@MelvinBot
Copy link

@danieldoglas 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]

@danieldoglas
Copy link
Contributor

Assigning @puneetlath and @eVoloshchak since this is their issue. not sure why Melving added me.

@danieldoglas danieldoglas removed their request for review March 6, 2023 10:43
@Litande Litande requested review from puneetlath and removed request for eVoloshchak March 6, 2023 18:24
@Litande
Copy link
Author

Litande commented Mar 6, 2023

@puneetlath not sure why @eVoloshchak was remnoved from reviewers

@puneetlath puneetlath requested a review from eVoloshchak March 6, 2023 18:29
@Litande
Copy link
Author

Litande commented Mar 7, 2023

@puneetlath @eVoloshchak i have fixed lint issues

@puneetlath
Copy link
Contributor

@eVoloshchak can you take the first pass?

@eVoloshchak
Copy link
Contributor

@eVoloshchak can you take the first pass?

Sure, reviewing in a couple of hours

@eVoloshchak
Copy link
Contributor

@Litande, please include videos for all the platforms. They aren't affected, but this is a good way to double-check that

@Litande
Copy link
Author

Litande commented Mar 7, 2023

@eVoloshchak updated the videos on all platforms, should i request review again? it seems to remove users when i do it.

Thanks.

@eVoloshchak
Copy link
Contributor

eVoloshchak commented Mar 7, 2023

should i request review again? it seems to remove users when i do it.

No, it remains visible in Review requests, so you don't have to request a review each time
UPD: you can just drag and drop videos into github, so they can be displayed in the built-in player

@eVoloshchak
Copy link
Contributor

eVoloshchak commented Mar 7, 2023

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 / Chrome
    • iOS / native
    • iOS / 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 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 correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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(themeColors.componentBG)
  • 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 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

Web
Screen.Recording.2023-03-08.at.12.49.35.mov
Mobile Web - Chrome
video_2023-03-08_12-56-11.mp4
Mobile Web - Safari
IMG_0006.MP4
Desktop
Screen.Recording.2023-03-08.at.12.53.55.mov
iOS
IMG_0007.MP4
Android
video_2023-03-08_12-56-07.mp4

}

flatListRef.current.scrollToIndex(lastIndex);
lastIndex = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do this? I might be wrong, but I think we don't need to set lastIndex to undefined and don't need the if (lastIndex === undefined) check. Could you verify that, please?

Copy link
Author

Choose a reason for hiding this comment

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

The uncontrolled behavior requires this because the events aren't chained and can happen asynchronously the check validates and clearance of this value validates the action won't happen again if not actually needed

Litande and others added 4 commits March 8, 2023 07:12
Co-authored-by: Eugene Voloshchak <copyreading@gmail.com>
Co-authored-by: Eugene Voloshchak <copyreading@gmail.com>
Co-authored-by: Eugene Voloshchak <copyreading@gmail.com>
@Litande
Copy link
Author

Litande commented Mar 8, 2023

@eVoloshchak updated everything and left comments

@eVoloshchak
Copy link
Contributor

@Litande, some of the links in your Screenshots/Videos are broken, there are no videos.
You don't need to use a separate video hosting, you can just drag a file directly into GitHub comment

Screen.Recording.2023-03-08.at.12.55.35.mov

Copy link
Contributor

@eVoloshchak eVoloshchak left a comment

Choose a reason for hiding this comment

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

Code looks good to me, tests well on iOS too.
There is the same behavior on Mobile Safari, Web and Desktop (you can see it in videos here), but it was present before this PR (and it changes index.ios file only). We probably need to tackle it as a separate issue.
cc: @puneetlath

@Litande
Copy link
Author

Litande commented Mar 8, 2023

@eVoloshchak will update the videos in a hour like this

@Litande
Copy link
Author

Litande commented Mar 8, 2023

@eVoloshchak updated the videos.

@puneetlath
Copy link
Contributor

There is the same behavior on Mobile Safari, Web and Desktop (you can see it in videos #15662 (comment)), but it was present before this PR (and it changes index.ios file only). We probably need to tackle it as a separate issue.

Hm, interesting. Will the solution for tackling it on those platforms be different?

@eVoloshchak
Copy link
Contributor

Hm, interesting. Will the solution for tackling it on those platforms be different?

Yes. I've tried to apply the fix to all platforms, but the behavior is still the same

@puneetlath
Copy link
Contributor

Ok, that's interesting. Is there a more holistic solution that we could do that would fix the issue on iOS and other platforms? Or do we need to take a platform-specific approach?

Don't worry @Litande, we'll pay you out for this no matter what direction we choose to go. I just want to make sure that this is indeed the best approach.

@Litande
Copy link
Author

Litande commented Mar 8, 2023

I can try to check other platforms the question is what the expected behavior if on switch to edit to execute the scroll because in most of them it don't scroll at all as it seems

@eVoloshchak
Copy link
Contributor

eVoloshchak commented Mar 8, 2023

@puneetlath, it turns out we explicitly disable the scroll if editing on web and desktop

function scrollToIndex(index, isEditing) {
    if (isEditing) {
        return;
    }

    flatListRef.current.scrollToIndex(index);
}

I deleted this line and everything seems to work fine, but this logic was added for some reason.
It was added in #2320. I can't access the issue linked in that PR, all I found is this comment

Scroll to the provided index. On non-native implementations we do not want to scroll when we are scrolling because we are editing a comment.

@Litande
Copy link
Author

Litande commented Mar 8, 2023

@puneetlath @eVoloshchak it seems to me on web and desktop the assumption is that if an item is fully in view there is no need to scroll it, but it seems not to handle the edge cases (in case the item pressed is partially covered from top or bottom) also in general the "mobile - web" doesn't have a lot of space and those the same issue may happen much more frequently.

@puneetlath
Copy link
Contributor

Looks like you added that two years ago @yuwenmemon. Do you remember why that was?

@yuwenmemon
Copy link
Contributor

Do you remember why that was?

Yeah, we didn't want the scroll to move if you were editing. We just wanted you to be able to "edit in place" effectively. Small UX choice not sure if we're married to it anymore.

@puneetlath
Copy link
Contributor

Ah that makes sense. So like if new messages come in while you're editing, we don't want the comment you're editing to move.

@puneetlath
Copy link
Contributor

I'm still thinking, however, that we should try to solve this in a cross-platform way, rather than just doing it for iOS. What do you think @Litande and @eVoloshchak?

@eVoloshchak
Copy link
Contributor

I'm still thinking, however, that we should try to solve this in a cross-platform way, rather than just doing it for iOS. What do you think @Litande and @eVoloshchak?

The only thing we can do is remove

    if (isEditing) {
        return;
    }

It works ok for me, haven't found any issues.
We can implement it here or raise a discussion in slack, since this is caused by a different reason than our issue

@eVoloshchak
Copy link
Contributor

@puneetlath, bump on the above

@Litande
Copy link
Author

Litande commented Mar 20, 2023

@eVoloshchak @puneetlath i am ok with this, but not sure if the desition is correct from behavior point of view.

@eVoloshchak
Copy link
Contributor

@puneetlath, should we proceed with the current bevavior (scroll is disabled while editing on web/desktop) or enable it?

@puneetlath
Copy link
Contributor

My apologies for the delay! Not sure how this slipped through the cracks for me for so long. I think what we want ideally on all platforms:

  1. When you edit a comment, scroll if needed so that the full input field and save/cancel buttons are visible
  2. While editing, don't allow the chat to scroll if new messages come in

I think we should approach that in a cross-platofrm way. So I think we should go ahead and pay out @Litande and @eVoloshchak for this, since the work that was initially agreed upon was done. But let's close the PR and open a new issue to handle this in a more cross-platform way.

Thoughts on that approach @eVoloshchak?

@eVoloshchak
Copy link
Contributor

  1. When you edit a comment, scroll if needed so that the full input field and save/cancel buttons are visible
  2. While editing, don't allow the chat to scroll if new messages come in

Yeah, I argee that should be the correct behavior
That means this issue might appear on web (on safari mobile) and we'll need to use this fix for all the platforms, going to check this

@puneetlath
Copy link
Contributor

Ok opened new issue here: #16601

@puneetlath puneetlath closed this Mar 28, 2023
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.

6 participants