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

Fixes implicit scroll to top on android when orientation changes #187

Merged
merged 4 commits into from
Mar 16, 2022

Conversation

naqvitalha
Copy link
Collaborator

@naqvitalha naqvitalha commented Mar 16, 2022

Description

When orientation is changed for the first time on Android the list scrolls to the top. This does not happen on iOS. While debugging I noticed that this issue started to happen when we stopped using RLV's render footer.

RLV's footer is rendered separately from the list items so on the first render which is used to measure the scrollview this footer would give some content to scrollview which was non zero in size. I don't know the reason but if content is of zero height when scrollview mounts then on its size change it raises a scroll event with offset 0px. This looks like an issue in ScrollView and not the list.

To solve this I've to set some min size to the content. More context is present in comments with the changes.

Reviewers’ hat-rack 🎩

  • Open twitter list (flashlist version on android), scroll and change to landscape. On main branch it will scroll to top while here it won't. This issue only happens on first orientation change.

Video

Screen.Recording.2022-03-15.at.23.59.58.mov

Checklist

@@ -360,7 +362,15 @@ class FlashList<T> extends React.PureComponent<
);
}

private validateListSize(event: LayoutChangeEvent) {
const { height, width } = event.nativeEvent.layout;
if (Math.floor(height) <= 1 || Math.floor(width) <= 1) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have to give a non zero size and I've used 1. This warning will show up if lists' either dimension <2px. I need floor because onLayout can have slightly higher values in some cases.

I also like the fact that we've moved to a warning instead of an error. I think this is fair because if a list is rendered with such a small size it most like means parent uses flex-start or something similar. My intent is to only catch this issue thus I want to use smallest value possible.

We cannot skip the warning because bounded size issue happens quite a lot and showing the solution right there helps developers.

@naqvitalha
Copy link
Collaborator Author

Please do review this and merge if everything looks good!

Copy link
Contributor

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

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

Note to self and anybody else re: 🎩 - you have turn on auto-rotate in the emulator's settings 😅

I have 🎩 'd this and looks good 👏 ✅

src/FlashList.tsx Show resolved Hide resolved
src/errors/Warnings.ts Outdated Show resolved Hide resolved
src/FlashList.tsx Show resolved Hide resolved
@naqvitalha naqvitalha merged commit 441ed04 into main Mar 16, 2022
@naqvitalha naqvitalha deleted the fixImplicitScrollToTop branch March 16, 2022 14:35
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.

2 participants