Description
FlatList automatically scrolls after change data and adds new data in the front or middle of the data list.
It only works correctly when adds new item to the end of list
I checked scroll offset and understand that FlatList scrolls to keep the latest content Y offset
I mean when the content size changes, the latest Y offset now is not where the user was before! but FlatList scrolls to it
React Native version:
react-native: 0.59.4
System:
OS: Windows 7
CPU: (2) x64 Intel(R) Pentium(R) CPU G4400 @ 3.30GHz
Memory: 310.09 MB / 3.87 GB
Binaries:
Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.2.0.0 AI-181.5540.7.32.5056338
Describe what you expected to happen:
It shouldn't scroll to new position when I add new items to list, and should keep latest position where user was
Example code:
<FlatList
inverted
style={{flex: 1}}
data={this.data}
keyExtractor={(item, index) => item.id}
renderItem={this.renderItem}
ref={ref => this.flatList = ref}
/>
Code that adds new items to list:
this.data = [ ...newItems, ...this.data ];
Activity
sgtpepper43 commentedon Jun 20, 2019
If you only need this fixed in
ios, there's an undocumented prop maintainVisibleContentPosition onScrollViewthat ought to do what you want. Unfortunately it doesn't work on android. I've been trying to solve this problem for the last two days in my own code and it's a freaking nightmare.SiSa68 commentedon Jun 22, 2019
@sgtpepper43 Thank you for participate
I need in both android and iOS.
I find workaround by keep latest y offset with onScroll and also save content height before and after adding new items with onContentSizeChange and calculate the difference of content height, and set new y offset to the latest y offset + content height difference!
But its not a good way, because it has UX problem. Firstly it scrolls down and after that scrolls back to the latest position
And it's not working when I want to load my list item from realm database
There should be a simpler way to do this and I don't understand why there is not?!
sgtpepper43 commentedon Jun 22, 2019
That's the same point I'm at 😩 I was going to try and fix it, but it's taken longer to try to get the Android code building and running in our app then writing the fix itself will take... I still haven't gotten it to compile. So I'm giving up on that.
SudoPlz commentedon Jul 1, 2019
fyi, I've asked the same thing here https://stackoverflow.com/questions/56707931/prepending-data-to-a-flatlist-always-shows-the-first-child/56837491#56837491
No actual fixes so far.
Leaving that here for future reference.
winardis commentedon Jul 18, 2019
having the same issue here on trying to prepend data to my datasource,
i found "maintainVisibleContentPosition" but that only works for IOS, Android is not supported
have you guys found any other solutions on this without manually scrollToIndex of course
kirillpisarev commentedon Jul 22, 2019
I was afraid that there is no straightforward way to achieve this, but at the moment after a couple of days of trying to implement this feature, it looks like RN is not an appropriate tool to implement chat apps.
SiSa68 commentedon Jul 22, 2019
I can not believe that they are not support this feature at all!!!
I found RecyclerListView
It might solve this problem, But I didn't currently have the opportunity to test it
If someone has an opportunity, please test and give the result to the React Native community!
jmacioszek commentedon Jul 31, 2019
That's an issue for me as well, would be nice to have this working with SectionList.
AVert commentedon Aug 14, 2019
Have same problem Guys ((
maintainVisibleContentPosition not work on Android
SudoPlz commentedon Aug 14, 2019
I created a ticket in Canny, please upvote, this has to get fixed soon https://react-native.canny.io/feature-requests/p/allow-prepending-new-items-to-flatlists-without-side-effects
AVert commentedon Aug 26, 2019
@sahrens
Could you please triage this? This is a regression/bug, right? If so, any advice how to fix it? Thanks!
AVert commentedon Aug 28, 2019
i check this same way not work
AVert commentedon Aug 28, 2019
@naqvitalha can you change you component to mak it work as we need?
162 remaining items
react-native-bot commentedon Mar 31, 2026
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
soheb-kachara commentedon Mar 31, 2026
2026 and still not solved ?
Vishal-D4 commentedon Apr 6, 2026
Use FlashList instead
vovakovalchukk commentedon May 16, 2026
2026 still not solved, crazy..
aarononeal commentedon May 17, 2026
Root Cause Analysis: FlatList Auto-Scroll on Item Prepend (Issue #25239)
The Issue
FlatList automatically scrolls when new items are prepended (added to the front/middle) of the data list. The scroll position shifts because FlatList tries to maintain the current viewport Y offset, but when items are added before the visible items, that Y offset no longer corresponds to the same content.
The comment referenced (by @vovakovalchukk, May 2026): Notes this 7-year-old issue remains unfixed.
Root Cause
The root cause is a fundamental algorithmic limitation in how
maintainVisibleContentPositionworks, combined with FlatList's view recycling. The algorithm tracks a single view's frame position and applies a delta correction on layout changes — but this breaks down in several ways with FlatList's virtualized rendering.maintainVisibleContentPositionAlgorithm and Why It FailsThe algorithm (on both iOS and Android) works like this:
prevFirstVisibleFrame)deltaY = newFrame.top - prevFirstVisibleFrame.topscrollY + deltaYThis algorithm fails for prepend scenarios because:
View recycling (FlatList's windowing): FlatList only keeps ~7-15 items mounted at a time (controlled by
windowSize). When you prepend more items than the visible window, the previously-stored view reference becomes stale — the view has been recycled for a different data item. The WeakReference may even point to a view that's no longer in the hierarchy. (@jjd314, Oct 2020: "if you add more than (windowSize-1)/2 items to the top of your data, it loses the scroll position (because the previously visible item will have been reclaimed)")Single-view tracking: The algorithm only tracks ONE view. When items are prepended, the tracked view may shift off-screen, and no other visible views are monitored. The algorithm has no fallback.
Variable-height items: The delta calculation assumes items maintain consistent vertical positions. With variable-height items (common in chat feeds), the delta computed from one layout change doesn't accurately predict the shift from the next.
Timing/debounce issues: Android implementation uses a 100ms debounce on scroll changes (@maxoumime, Feb 2021). This can miss rapid layout changes or introduce visible lag. (@Strate, Sep 2020: "I would prefer @stackia's implementation, because it matches iOS implementation, and do not use debounce, which leads to possible lags in implementation")
Inertia scroll interference (Android): When
OverScrolleris animating (user flung the list), callingsetScrollY()doesn't update the internalOverScrollerstate. The scroll position appears to jump back when inertia resumes. (@Strate, Sep 2020: "on android just callingsetScrollY()does not affect scroll animation - if list scrolling by inertia via OverScroller class, altering scrollY on ScrollView does not affects internal values inandroid.widget.OverScroller- so you need to stop it and re-launch again.")Inverted lists: The algorithm doesn't account for inverted scroll direction (where new items appear at the "bottom" visually but are prepended to the data array).
Evidence from the issue comments:
Why It Happens (Technical Details)
maintainVisibleContentPositionprop is designed to solve this by anchoring to a specific index/first visible item rather than a raw pixel offset — but it only works on iOSWhy Workarounds Fail
Users tried several approaches, all with problems:
onScroll+onContentSizeChange): Causes a visible flash — scrolls down then backmaintainVisibleContentPosition: Doesn't work reliably on iOS (view recycling, single-view tracking); didn't exist on Android until PR Support forScrollView.maintainVisibleContentPositionon Android #29466 (which had unresolved OverScroller issues)minIndexForVisibledidn't work; never submitted as a PRThe PR That Almost Fixed It (#29466)
A PR titled "Support for
ScrollView.maintainVisibleContentPositionon Android" was opened in July 2020 by @maxoumime. It was:ReactScrollView,ReactHorizontalScrollView, and their managersIt was never merged. The PR was closed in June 2023 without resolution.
Known issues raised during review (never addressed):
setScrollY()does not affect scroll animation - if list scrolling by inertia via OverScroller class, altering scrollY on ScrollView does not affects internal values inandroid.widget.OverScroller- so you need to stop it and re-launch again."The PR author (@maxoumime, Feb 2021) acknowledged the OverScroller issue but said "I don't think this PR should aim at fixing this though." The React Native team never addressed any of these concerns and the PR was eventually closed as stale.
Community workarounds that emerged:
@stream-io/flat-list-mvcpnpm package (Dec 2020) based on @stackia's implementationSummary
maintainVisibleContentPositionalgorithm uses single-view frame tracking that breaks with FlatList's view recycling; Android implementation (PR #29466) had unresolved OverScroller state issueshotairbag commentedon Jun 2, 2026
Any update??
aarononeal commentedon Jun 2, 2026
In my patch branch, I implemented the fix to recompute first-visible views after every layout change, which addressed the stale view problem. That seemed to fix positioning as long as prepends are smaller than
windowSize. I then added a bunch of additional test coverage to verify each scenario.At that point it was easy to reproduce the issue of adding more items than
windowSize, which pushes the anchor item out of view, recycles the item, and corrupts the positioning again. I'm still trying to resolve that, and unfortunately it might require a new strategy I haven't discovered yet.Latent bugs like divide by zero or missed clears affecting layout are slowing progress because I discover them as I add instrumentation:
Turns out that fix was more impactful than I expected. Between my first patch, some anchor frame fixes, and this one, it appears to be working now: vertical, horizontal, inverted, and prepend > windowSize. I'll clean up the patch and tests and get it submitted.
aarononeal commentedon Jun 9, 2026
Quick update-- I expanded test coverage and I'm seeing differences between iOS and Android. There appear to be some functional edge cases still I haven't bottomed out.
aarononeal commentedon Jun 13, 2026
Working on a few doc updates before I submit the PR, but code changes are here if anyone wants to review or test in the interim.
main...aarononeal:fork-facebook-react-native:fix/mvcp-corrections-and-tests
aarononeal commentedon Jun 19, 2026
PR submitted. Please test to see if it fixes things for you. I added tests and docs for this area. If I didn't cover your specific scenario, send a repro or test and I'll take a look when I can.
Fix maintainVisibleContentPosition calculations and add tests + docs [f…
Fix maintainVisibleContentPosition calculations and add tests + docs [f…