Fix sticky header apprearance in flashlist v2#1952
Fix sticky header apprearance in flashlist v2#1952phamxdinhhien wants to merge 2 commits intoShopify:mainfrom
Conversation
|
Can you provide an expo snack showcasing the problem? I check our contact sample and it works just fine with padding applied. |
I'm not OP but I think there's a repro here #1959 |
|
@naqvitalha here’s the Snack https://snack.expo.dev/@rodolfosilva/laughing-red-watermelon?platform=ios This issue only occurs on native, it works fine on the web. |
|
@naqvitalha another issue related to this is that the header becomes sticky too often. |
|
I've applied this patch, but it doesn't fix the issue. |
ada29af to
660b77d
Compare
|
Closing — this is superseded by PR #2105 (merged), which fixed the root cause by correcting |
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
firstItemOffsetis applied to the RecyclerView.Problem
When using
stickyHeaderIndiceswith 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.tsxwere not consistently handlingfirstItemOffset:firstItemOffsetfirstItemOffset, 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):
firstItemOffsetfrom item Y positions when comparing against scroll offsetRemoving double-counting in next sticky calculation (line 109):
firstItemOffsetsince it's already included in the layout Y positionChanges
src/recyclerview/components/StickyHeaders.tsxTesting
contentContainerStylewithpaddingTopcontentInseton iOSImpact
firstItemOffset> 0