1
My intention is to have lines with two items, and these items should have a width according to the screen size, ie screen 500 , I calculate 500/2 - espaços
.
It would be something like this.
My code:
const columns = 2;
const margin = vw(1);
const spacing = (columns + 1) / columns * margin;
function vw(percentageWidth) {
return Dimensions.get('window').width * (percentageWidth / 100);
}
export default class SearchPesquisa extends Component {
cards () {
return this.props.produtos.map((item, indice) => {
return(
<View key={i} style={styles.cell}>
<Card>
<CardItem style={{ height: 280, borderRadius: 4 }}>
</CardItem>
</Card>
</View>
)
})
}
render() {
return (
<View style={styles.container}>
<ScrollView>
{ this.cards() }
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'flex-start'
},
cell: {
width: vw(100) / columns - spacing
}
});
Explaining:
flexDirection:'row'
display direction of my items.columns
number of columns to be displayed.vw
margin percentage calculation, in the examplevw(1)
will be 1 percentspacing
only one space.
My example is: Viewport: ~411, Margin: ~4.11, Spacing: ~6.17, Widcard:199.54
Problem: Each card is staying in a row.
An example only in CSS/HTML would help you?
– hugocsl
@hugocsl I do not know, can I apply it here? Put there what I warn you if it worked :)
– Marconi
Will your cards have a fixed width? The container the cards are inside will have a defined width?
– hugocsl