fix(scroll): correct inverted list rendering and wheel direction on web#2331
Open
HuuNguyen312 wants to merge 1 commit into
Open
fix(scroll): correct inverted list rendering and wheel direction on web#2331HuuNguyen312 wants to merge 1 commit into
HuuNguyen312 wants to merge 1 commit into
Conversation
On web, inverted lists are flipped with transform: scaleY(-1). This broke two things: - measureFirstChildLayout read mirrored getBoundingClientRect coordinates, so firstItemOffset grew with scroll and scrollOffset went negative, freezing the engaged index (~20 items rendered, then blank). Measure from the bottom edge when the container is vertically flipped so firstItemOffset stays ~0. - The native mouse wheel is not flipped, so it scrolled the wrong way. Add a web-only useInvertedWheelFix hook that re-inverts the wheel delta on the scroll node (no-op on native). Native behavior is unchanged: measureLayout.ts and the native hook variant are untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes inverted list rendering and mouse-wheel direction on web (e.g. Electron). Native is unaffected.
On web, inverted lists are flipped with
transform: scaleY(-1)(scaleX(-1)when horizontal). This broke two things:1. Rendering froze (~20 items, then blank)
measureFirstChildLayoutread mirroredgetBoundingClientRectcoordinates, sofirstItemOffsetgrew with scroll instead of staying~0. The internalscrollOffset(y - firstItemOffset) went negative →getVisibleLayoutsclamped to index0→ the engaged index froze →renderItemstopped being called while scrolling.Fix: detect the
scaleY(-1)transform and measure from the bottom edge when flipped, sofirstItemOffsetstays~0(matching non-inverted).2. Mouse wheel scrolled the wrong way
The native wheel delta is not flipped by the container transform, so it scrolled opposite to the content.
Fix: a web-only
useInvertedWheelFixhook re-inverts the wheel delta on the scroll node (-= deltaY, or-= deltaXwhen horizontal). SettingscrollTop/scrollLeftstill fires the scroll event, so virtualization keeps working.Affected package:
@shopify/flash-listChanged files
src/recyclerview/utils/measureLayout.web.tsisVerticallyFlipped, measure from bottom when flippedsrc/recyclerview/hooks/useInvertedWheelFix.web.tssrc/recyclerview/hooks/useInvertedWheelFix.tssrc/recyclerview/RecyclerView.tsxReviewers' hat-rack 🎩
renderItemfires as expectedfirstItemOffsetstays~0while scrolling an inverted list on web (was growing1057 → 4009 → 9923before the fix)