📅  最后修改于: 2023-12-03 15:34:38.580000             🧑  作者: Mango
When working with React Native's FlatList, you might come across situations where you need to add some space between the list items and the bottom of the screen. This can be achieved using the style
prop and setting a marginBottom
value.
The style
prop can be used to apply styles to the FlatList component. To add a margin bottom, simply set the marginBottom
property of the style object.
<FlatList
data={[{ key: 'item1' }, { key: 'item2' }, { key: 'item3' }]}
renderItem={({ item }) => <Text>{item.key}</Text>}
style={{ marginBottom: 10 }}
/>
This will add a 10px margin bottom to the FlatList component.
If you want to apply different margins to individual items in the list, you can do so by modifying the style of the renderItem
component.
<FlatList
data={[{ key: 'item1' }, { key: 'item2' }, { key: 'item3' }]}
renderItem={({ item }) => (
<View style={{ marginBottom: item.key === 'item3' ? 20 : 10 }}>
<Text>{item.key}</Text>
</View>
)}
/>
This will add a 20px margin bottom to the last item in the list, and a 10px margin bottom to all other items.
Adding a margin bottom to a React Native FlatList is a simple task that can be accomplished using the style
prop. By modifying the style of the renderItem
component, different margins can be applied to individual list items.