ScrollToEnd after update data for Flatlist

Tuan Nguyen Quoc picture Tuan Nguyen Quoc · Sep 19, 2017 · Viewed 11.2k times · Source

I'm making a chat box with Flatlist. I want to add a new item to data then scroll to bottom of list. I use scrollToEnd method but it did not work. How can I do this?

Answer

Ourabi picture Ourabi · Mar 8, 2019

I found a better solution,scrollToEnd() is not working because it is triggered before the change is made to the FlatList.
Since it inherits from ScrollView the best way here is to call scrollToEnd() in onContentSizeChange like so :

<FlatList
            ref = "flatList"
            onContentSizeChange={()=> this.refs.flatList.scrollToEnd()} />