Fix: contentContainerStyle paddingTop ignored on initial render (iOS)#403
Open
Kasendwa wants to merge 1 commit intoLegendApp:mainfrom
Open
Fix: contentContainerStyle paddingTop ignored on initial render (iOS)#403Kasendwa wants to merge 1 commit intoLegendApp:mainfrom
contentContainerStyle paddingTop ignored on initial render (iOS)#403Kasendwa wants to merge 1 commit intoLegendApp:mainfrom
Conversation
…dApp#392) When a LegendList has paddingTop in contentContainerStyle (or a ListHeaderComponent), the list was rendering with the padding scrolled out of view on the first render. This happened because the MVCP logic saw the padding change from 0 to the actual value and tried to compensate, even though nothing had actually scrolled yet. Fixed by checking state.hasScrolled before applying the adjustment, so we only compensate for padding changes after the user has scrolled. Added regression test covering the first-render and post-scroll cases.
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.
Closes #392
What's the problem?
On iOS, when a
LegendList(orAnimatedLegendList) haspaddingTopincontentContainerStyleor uses aListHeaderComponent, the list renders with the padding/header scrolled out of view on the first render. The user sees the content as if it's already scrolled past the top. Scrolling up manually reveals the padding/header, and everything works fine from that point on.This only affects iOS — Android is unaffected.
Why does it happen?
In
initializeStateVars, the MVCP (maintainVisibleContentPosition) logic detects a padding "change" on first render — from0(the initial default) to the actual value (e.g.100) — and callsrequestAdjustto compensate. But there's nothing to compensate for on the first render; the list hasn't scrolled yet.The existing guard (
prevPaddingTop !== undefined) was meant to catch this, but it fails becausestylePaddingTopis initialized to0in the state context, notundefined.How is it fixed?
Added a
state.hasScrolledcheck to the condition:if ( maintainVisibleContentPosition && paddingDiff && prevPaddingTop !== undefined && + state.hasScrolled && Platform.OS === "ios" ) {state.hasScrolledisfalseuntil the user actually scrolls (set inonScrollAction), so the adjustment is skipped on first render. After the user scrolls, dynamic padding changes are still correctly compensated.Testing
__tests__/core/initializeStateVars-mvcp.test.tscovering:Reproduction
LegendListwithcontentContainerStyle={{ paddingTop: 100 }}or aListHeaderComponentPerformance Impact
None. This adds a single boolean read (
state.hasScrolled) to an existing conditional. No new allocations, renders, or layout changes.