-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FlatList automatically scrolls after adding new items #25239
Comments
If you only need this fixed in |
@sgtpepper43 Thank you for participate But its not a good way, because it has UX problem. Firstly it scrolls down and after that scrolls back to the latest position There should be a simpler way to do this and I don't understand why there is not?! |
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. |
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. |
having the same issue here on trying to prepend data to my datasource, |
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. |
I can not believe that they are not support this feature at all!!! |
That's an issue for me as well, would be nice to have this working with SectionList. |
Have same problem Guys (( |
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 |
@sahrens |
i check this same way not work
|
@naqvitalha can you change you component to mak it work as we need? |
I try this - no way |
@AVert |
Clarification: I'm creating a chat app which will append pages of messages as user scrolls up, and prepend newly received messages to the bottom. My solution using an inverted flatlist was to not render newly received messages at the bottom, unless/until the user is scrolled to the bottom.
This gave me the best user experience, since maintainVisibleContentPosition does not work on android, so I did not use it at all. |
@dmkerfont I don't really get it, what problem does this solve? It looks like you're not "prepending" data, looks like you're only appending. Isn't the issue only apparent when someone tries to prepend data (and thus get's scrolled on a wrong date?) Thanks |
@SudoPlz When a new message comes in, prepending it to the front of the list will cause the data shifting issue as the indexes are reset. Instead of prepending every message that comes in, I'm checking if the user is at/near the bottom or if they are scrolled up a significant distance. If at bottom, then prepend and scroll down. If user reaches bottom, through a manual scroll or pressing a button like a 'New Message' indicator, then simply prepend the queued messages. I have no experience with native code so I have no desire to implement maintainVisibleContentPosition at this time, but this is a decent workaround. |
@dmkerfont interesting, is it too much to ask for some visual example? I've taken the time to replicate what you said with numbers below, does it look right? Example: Inverted flatlist
user manually scrolls to the bottom, then:
New items [4][5][6] get prepended:
so the user ends up seeing [6] now (which is now index 0) . Then as an extra step the user get's scrolled to 0 again?
I appreciate your time, thanks. |
Shoot... You are right. If I'm scrolled up (and want my scroll position preserved), then I build my list of new messages. Perhaps this alternative isn't worth all the effort after all. :(
If you've done any paging, you will have noticed that adding items to the end of the list ( bottom for regular flatlist ) works as expected. This is the same when appending (top) to an inverted flatlist. |
Ok cool, please let me know if you find a way to make the user see [4] instead (the next item). |
What’s the story with this issue? Every time the data source on the flat list changes, say once new data is fetched or prended to the list it resets the scroll position. I’m building some sort of user feed, so I need to be able to update the data source without messing up the users scroll position. Is this possible at all with react native? The maintainVisibleContentPosition prop seems to do nothing for me. |
Edit: As Sisa68 noted, I misunderstood the struggle here. Mb |
@jakovB777 I think our case are different from yours! |
Same problem =(( We add new items to the start of array and position is still 0 |
anyone fix it? |
i use https://github.com/bolan9999/react-native-largelist and same issue. |
@ahmed-sharief5 but i believe this will affect the app performance, specially for people with large data/paginated data. |
@benkhlifafahmi otherwise use
Because it determines the maximum number of items to render in each batch when new items are loaded during scrolling. A higher value can reduce the number of render cycles and improve performance |
Haha, any fix for November 2023? |
I'm looking for a solution too without creating own carousel... Some time ago it worked for me with 'maintainVisibleContentPosition' but for some reason it stopped... |
did you check this? |
How has that issue never been resolved after so many years? |
I found a solution. Just put your It worked for me android and ios |
You sure? It doesn't make sense in terms of fixing the following issue... |
Yes @RobertMrowiec . I spent more than 2 hours searching for a solution, and then I just found one of my old projects with that implemented. I had a |
I can fix this issue using the new API maintainvisiblecontentposition has been added to Android with https://github.com/facebook/react-native/pulls?q=is%3Apr+author%3Ajanicduplessis+is%3Aclosed+maintain. The issue is pretty old. Anybody still interested in this? Thanks |
There is a new popular component FlashList with 4.5k stars. Did you try to use that component? If yes, why did you decide to keep using FlatList from react-native? Thanks |
issue persists |
This has not been implemented in FlashList unfortunately. There's an open pull that (supposedly, have not tested) adds it, but it has not been reviewed as of current. |
I've managed to fix similar scroll issue in my "chat app" by making all |
2024 still not solved? wow |
2024 still not solved? wow |
this worked for me:
|
Fortunate you had a simpler case but I think most of us were interested in a solution that specifically doesn't visually scroll the list when new content is added. |
Any solutions? Can't believe it's still open lol.. |
try use VirtualizedList insted of Flatlist as per 2024 it's worked |
|
Still unable to find a solution. Does anyone know of some solution to this? |
Well I was hoping this would've beem resolved somewhere in the last 5 years. There still doesn't seem to be a proper solution... |
Unfortunately it's had an issue for me too |
There are over a hundreds participants in this issue: a bump is the last thing it needs. The react-native team is definitely well aware and it's simply not in their priorities at this point. |
Maybe this drop will move the needle (crying sarcastically) |
Given how critical this kind of control is for displaying feed-based information, such as with social network content, it really undermines the value of the whole React Native platform to hit a blocker like this where you can't support infinite bi-directional scrolling of variable sized items. My attempts at workarounds and building custom controls to perform offscreen sizing have so far produced mediocre results. Would be great if someone more versed in the stack internals could take another look at this longstanding issue. |
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 ];
The text was updated successfully, but these errors were encountered: