Basically, my flatlist is in 2 columns. But if there is an odd number of item the last row will be stretch.
This is my Flatlist coding
export default class Cluster1 extends Component{
render(){
const getClusterByName = (name) =>
Cluster.find(cluster => cluster.hasOwnProperty(name))[name]
return(
<ScrollView>
<FlatList
numColumns= {2}
data={getClusterByName('cluster1')}
renderItem={({item,index})=>{
return(
<FlatListItem item={item} index={index}>
</FlatListItem>);
}}
>
</FlatList>
</ScrollView>
);
}
Then this is my FlatlistItem
class FlatListItem extends Component{
render(){
const {itemWidth} = this.props
return(
<View style={styles.list}>
<View>
<Text style={styles.itemText}>{this.props.item.name}</Text>
</View>
</View>
);
}
style code
const styles = StyleSheet.create({
list:{
flex:1,
borderRadius: 4,
borderWidth: 0.5,
width: 50,
padding:20,
backgroundColor: 'ghostwhite',
alignItems: 'center',
justifyContent: 'center',
margin: 2,
}
This will be the output as you can see the 'f' is stretch. I want it make the same width enter image description here
styles.list
code