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

Fix layout shift for multi-image posts #1673

Merged
merged 4 commits into from
Oct 12, 2023
Merged

Fix layout shift for multi-image posts #1673

merged 4 commits into from
Oct 12, 2023

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Oct 11, 2023

This has been bugging me for a while.

When we encounter a post with a gallery in feed (or profile — anywhere we display posts), we try to render it without images first, then measure the container's width, and then relayout images based on that width. As a result, there is a noticeable layout shift after the first render — even though the actual layout is entirely dependent on its container and doesn't even depend on the image sizes.

This shift is very bad both because it's visually noticeable (the screen always paints first with empty images) and because it screws the perf — everything below has to relayout again.

The fix is to use flexbox instead of manual calculations. I don't actually know flexbox so I had some help from ChatGPT with this. I might have uncovered a potential RN bug with how the gap property works, so there's a bit of a hack in the code. I've checked iOS, Android, and web (Chrome, FF, Safari), and the hack seems to work.

Before

Notice the layout jump after the glimmer.

ezgif.com-resize.3.mov

After

No layout jump after the glimmer.

ezgif.com-resize.4.mov

@gaearon gaearon requested a review from pfrazee October 11, 2023 21:41
@gaearon gaearon mentioned this pull request Oct 11, 2023
74 tasks
Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

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

Great stuff

@gaearon gaearon merged commit c2a1cf4 into main Oct 12, 2023
4 checks passed
@gaearon gaearon deleted the fix-layout-shift branch October 12, 2023 18:29
estrattonbailey added a commit that referenced this pull request Oct 13, 2023
…t-tags-into-app

* origin:
  Disable events on hidden bars (#1686)
  Fix profile layout shift (#1690)
  Don't re-render bars when showing/hiding them (#1691)
  Fix crash when scrolling down on the web (#1684)
  Make shell hide/show animation smoother (#1683)
  Fix layout shift for multi-image posts (#1673)
  bskyweb: add rate limiting to reduce DoSability
  use new zeed-dom version (#1671)
  1.53
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