fix feed scroll reset on device rotation
Remove the dead contentOffset prop from List and add maintainVisibleContentPosition to anchor the visible item across relayouts. The negative contentOffset was originally paired with a matching contentInset (web PR #230) so the first render sat flush under the floating header. PR #2216 swapped the inset for a paddingTop style but left the offset behind, where it's been dead on initial render since. On rotation its value changes (it's partly derived from the top safe -area inset), and RN re-applies it as an absolute scroll, snapping the list. maintainVisibleContentPosition then keeps the visible post pinned as items reflow to the new width. APP-2315 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -147,17 +147,19 @@ let List = forwardRef<ListMethods, ListProps>(
|
||||
)
|
||||
}
|
||||
|
||||
let contentOffset
|
||||
if (headerOffset != null) {
|
||||
style = addStyle(style, {
|
||||
paddingTop: headerOffset,
|
||||
})
|
||||
contentOffset = {x: 0, y: headerOffset * -1}
|
||||
}
|
||||
|
||||
return (
|
||||
<FlatList_INTERNAL
|
||||
showsVerticalScrollIndicator // overridable
|
||||
// Anchor the currently-visible item across content relayouts so that
|
||||
// changing the viewport size (e.g. device rotation) doesn't lose the
|
||||
// scroll position as items reflow to the new width.
|
||||
maintainVisibleContentPosition={{minIndexForVisible: 0}}
|
||||
onViewableItemsChanged={onViewableItemsChanged}
|
||||
viewabilityConfig={viewabilityConfig}
|
||||
{...props}
|
||||
@@ -170,7 +172,6 @@ let List = forwardRef<ListMethods, ListProps>(
|
||||
...props.scrollIndicatorInsets,
|
||||
}}
|
||||
indicatorStyle={t.scheme === 'dark' ? 'white' : 'black'}
|
||||
contentOffset={contentOffset}
|
||||
refreshControl={refreshControl}
|
||||
onScroll={scrollHandler}
|
||||
scrollsToTop={scrollsToTop}
|
||||
|
||||
Reference in New Issue
Block a user