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

Enable cached layouts #319

Merged
merged 14 commits into from
Apr 28, 2022
Merged

Enable cached layouts #319

merged 14 commits into from
Apr 28, 2022

Conversation

naqvitalha
Copy link
Collaborator

@naqvitalha naqvitalha commented Apr 14, 2022

Description

resolves #299

During orientation change, we were ignoring previous layouts that our layout manager had. This PR makes use of existing values to improve user experience. When item sizes change due to orientation change there are two possible scenarios -

  • Heights of the items change (e.g, our twitter sample). In this case this change will do no good.
  • Heights of the items do not change (e.g, our list sample). In this case reusing cached heights can improve the experience. A lot of lists have items whose heights do not change with orientation and this change can previous layout jumps like the ones you see in the video. A lot of lists in Shopify mobile are of this nature.

This PR also fixes the orientation change e2e test. More context inline.

Reviewers’ hat-rack 🎩

  • Open the first list as seen in the video
  • Scroll down and switch to landscape orientation
  • Scroll up
  • Scroll should be smooth with this PR. Layout will change randomly in main.

Screenshots or videos (if needed)

Screen.Recording.2022-04-27.at.13.42.11.mov

Checklist

@naqvitalha naqvitalha marked this pull request as ready for review April 27, 2022 20:44
@@ -156,7 +156,7 @@ describe("Twitter", () => {
});

const scrollAndRotate = async (id: string) => {
await element(by.id(id)).scroll(500, "down");
await element(by.id(id)).scroll(240, "down");
Copy link
Collaborator Author

@naqvitalha naqvitalha Apr 27, 2022

Choose a reason for hiding this comment

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

When we scroll beyond our render window and change orientation FlashList may not render all items and use cached heights. This means that currently visible items can be different from FlatList. And given the layout is async there's some inconsistency. I've changed the scroll offset to be less than our renderAheadOffset of 250. Hopefully, this will resolve the issue.
This is a quick fix and full solution will come with #18

...cachedLayouts[i],
// helps in updating the fixed dimension of layouts e.g, width in case of horizontal list
// updating them in advance will make sure layout manager won't try to fit more items in the same row or column
...layoutManager.getStyleOverridesForIndex(i),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Problem is that GridLayoutManager is based on WrapGridLayoutManager. After orientation change, if the existing widths of items are less than half of the list width then layout manager may try to fit more than one item in a row.
I'm correcting the layouts in advance to avoid this problem.

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.

🎩''d, looks good 👌

}

// making sure extra keys don't make their way to layout unnecessarily
expect(Object.keys(layout).length).toBe(6);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe worth using jest's toStrictEqual instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll discuss this with you separately

@naqvitalha naqvitalha merged commit 26a7931 into main Apr 28, 2022
@naqvitalha naqvitalha deleted the enableCachedLayouts branch April 28, 2022 16:57
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.

Reusing cached layout
2 participants