Fix sticky header apprearance in flashlist v2 #1952
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.
Fix: Sticky headers appearing prematurely when firstItemOffset is set
Description
Fixes an issue where sticky headers become active before the header item actually reaches the top of the list when
firstItemOffset
is applied to the RecyclerView.Problem
When using
stickyHeaderIndices
with a FlashList that has content insets, padding, or safe area adjustments (represented byfirstItemOffset
), the sticky header would appear too early—before the actual header item reached the top of the visible area. This created a jarring user experience where the sticky header appeared while the original header was still visible below it.Root Cause
The position calculations in
StickyHeaders.tsx
were not consistently handlingfirstItemOffset
:firstItemOffset
firstItemOffset
, causing it to be double-countedThis resulted in coordinate space misalignment, leading to premature sticky header activation.
Solution
This PR ensures all position comparisons happen in the same coordinate space by:
Normalizing item positions in binary search (line 95):
firstItemOffset
from item Y positions when comparing against scroll offsetRemoving double-counting in next sticky calculation (line 109):
firstItemOffset
since it's already included in the layout Y positionChanges
src/recyclerview/components/StickyHeaders.tsx
Testing
contentContainerStyle
withpaddingTop
contentInset
on iOSImpact
firstItemOffset
> 0