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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With