Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I render from Top when using FlatList inverted?

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
       <FlatList
          inverted
          data={[{key: 'a'}, {key: 'b'}]}
          renderItem={({item}) => <Text>{item.key}</Text>}
        />
        <Text>123</Text>
      </View>
    );
  }
}

Using inverted FlatList will render item from bottom to top when data is small.

When I run my expo snack a and b are at the bottom. I want this to start at the top.

Using the inverted option of FlatList Can I render from top when data is small?

https://snack.expo.io/r1eZBINGH

It does not matter if the inverted is removed if it is rendered at the top and the scroll can start at the bottom. Is there a workaround?

like image 343
oijafoijf asnjksdjn Avatar asked Jul 23 '19 09:07

oijafoijf asnjksdjn


People also ask

Can we use FlatList for list view and grid view both?

GridView can be used when we have to make a View Group that displays items in a two-dimensional, scrollable grid. The most usable example of the Grid is the image gallery where we have to showcase all the images. In this example, we will use FlatList to make our GridView. React Native FlatList is a simple list.

How do you make a horizontal FlatList?

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.

How do you optimize a FlatList performance?

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.

What is difference between FlatList and SectionList in React Native?

SectionList s are like FlatList s, but they can have section headers to separate groups of rows. SectionList s render each item in their input sections using the renderSectionHeader and renderItem prop. Each item in sections should be an object with a unique id (the key), and an array data of row data.


1 Answers

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
       <FlatList
          inverted
          data={[{key: 'a'}, {key: 'b'}]}
          contentContainerStyle={{
            flexGrow: 1, justifyContent: 'flex-end',
          }}
          renderItem={({item}) => <Text>{item.key}</Text>}
        />
        <Text>123</Text>
      </View>
    );
  }
}

I solved it by setting contentContainerStyle. Using fullscreen with flexGrow: 1 and justifyContent: 'flex-end' in the inverted state seems to start at the top when the data is small.

like image 56
oijafoijf asnjksdjn Avatar answered Oct 14 '22 22:10

oijafoijf asnjksdjn