Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 631
MendyK Avatar asked Jan 09 '18 03:01

MendyK


People also ask

How do you adjust the height of a FlatList?

To change the height of a FlatList in React Native, we can set the height of the View that we wrap around the FlatList . to set the height of the View to 300px to make the height of the FlatList 300px.

How do you optimize FlatList in React Native?

Use basic components​ The more complex your components are, the slower they will render. Try to avoid a lot of logic and nesting in your list items. If you are reusing this list item component a lot in your app, create a component only for your big lists and make them with as little logic and nesting as possible.

How do I remove items from FlatList in React Native?

Now let's understand it, First of all we would get the selected item Id on item click event, Now we would use Data. filter() method with selected ID and remove the selected id then update the Data again using State. This would remove selected item from FlatList in react native.

How do you set a FlatList horizontally?

To add a horizontal FlatList in React Native, we just set the horizontal prop of the FlatList to true . to add horizontal to FlatList . As a result, we can scroll through the FlatList items horizontally.


1 Answers

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}
/>
like image 119
needsleep Avatar answered Oct 15 '22 22:10

needsleep