fix: unexpected jumping of list while using sticky headers #47345
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.
Summary:
Part 1
Currently while using sticky headers inside
SectionList
orFlatList
we can be impacted by some wired jumping behaviour.This behaviour comes form 1 very small missed aspect when implementing sticky elements inside
ScrollView
.The issue is related to the fact that
ScrollView
is wrapping elements defined insidestickyHeaderIndices
with it's own component calledStickyHeaderComponent
that allows to manipulate and keep the header in the right coordinates.The pain point is that this component is component has
position: 'relative'
style defined.That causes the child component to return coordinates relative to that
StickyHeaderComponent
instead returning coordinates relative toScrollView root
like every non sticky children.Playground
https://snack.expo.dev/AWCvfHHhsHEUeoUXOPDJh
Part 2
VirtualisedList
which is a base for bothFlatList
andSectionList
is actively using onLayout coordinates to render spacers/placeholders for non visible components.To acquire that coordinates it creates another wrapper around each item inside
CellRenderer
which supplyonLayout
property.The simplified structure looks like this:
Summary
Now when onLayout is triggered inside
CellRenderer
which is rendered insideStickyHeaderComponent
the coordinates are relative toStickyHeaderComponent
and always returns offset as0
.Now when spacers/placeholders size calculation is happening it is doing the following math:
Changelog:
[GENERAL] [FIXED] - FlatList and SectionList odd jumping while using sticky headers
Test Plan:
ios-scrolling-issue.mov
ios-fixed-scrolling-issue.mov
android-scrolling-issue.mov
android-fixed-scrolling-issue.mp4
Reproduction code:
Click me to expand code!
Impacted versions: