How can I set the content offset of a FlatList in React Native?

MendyK picture MendyK · Jan 9, 2018 · Viewed 8.1k times · Source

I know that we can get the offset with

render() {
   return <FlatList
            onScroll={this.handleScroll}
          />
}

handleScroll = (event) => {
//get offset by using   
//event.nativeEvent.contentOffset 
}

But I'm not sure how to set it

Answer

needsleep picture needsleep · Feb 28, 2018

Unfortunately contentOffset didn't work for me. I ended up using contentContainerStyle that I found in the ScrollView documentation and it works great.

<FlatList 
  contentContainerStyle={{ paddingTop: 340 }} 
  data={data}
/>