Prevent scrolling Flatlist when adding new items

When adding data to a Flatlist (such as a subscription), it scrolls down, which leads to a very bad UX. Any idea on how this can be resolved?

+6
source share
1 answer

In fact, this should be handled at its own level, but I think that it is not handled, I solve my problem with the scroll offset and set it again after reloading the data as follows:

reloadData(flatListData){

   this.setState({
       flatListData: flatListData
   });

   requestAnimationFrame(() => {
         this.flatList.scrollToOffset({
                       animated: false,
                       offset: this.flatListLastOffset
             });
   });
}

...

<FlatList
     data={this.state.flatListData}
     ref={ref => this.flatList = ref}
     onScroll={(event: Object) => {
           this.flatListLastOffset = event.nativeEvent.contentOffset.y;
           }}
     horizontal={false}
     scrollEventThrottle={16}
 />

this is not the best solution, but fix my problem so far

+2
source

Source: https://habr.com/ru/post/1016759/


All Articles