Я использую карты в проекте React Native Expo. Карты создаются и размещаются динамически, но я хочу, чтобы 2 карты отображались в одной строке.
let data = [
{ id: "1", title: "First", desc: "Some desc", time: "4pm" },
{ id: "2", title: "Second", desc: "Some second desc", time: "5pm" },
];
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
products: data,
};
}
render() {
return (
<View style = {{display: "flex", flex: 1}}>
<View style = {{}}>
<FlatList
data = {this.state.products}
renderItem = {({ item }) => (
<TouchableOpacity>
<Card
style = {{
margin: 5,
}}
>
<View style = {styles.checkCards}>
<Text>{item.title}</Text>
</View>
</Card>
</TouchableOpacity>
)}
/>
</View>
</View>
)}}
Попробуйте дать FlatList numColumns = {2}
let data = [
{ id: '1', title: 'First', desc: 'Some desc', time: '4pm' },
{ id: '2', title: 'Second', desc: 'Some second desc', time: '5pm' },
];
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
products: data,
};
}
render() {
return (
<View style = {{ display: 'flex', flex: 1, marginTop: 24 }}>
<View style = {{}}>
<FlatList
numColumns = {2}
data = {this.state.products}
renderItem = {({ item }) => (
<TouchableOpacity style = {{ flex: 1, }}>
<Card
style = {{
margin: 5,
padding: 10,
}}>
<View style = {{}}>
<Text>{item.title}</Text>
</View>
</Card>
</TouchableOpacity>
)}
/>
</View>
</View>
);
}
}
Рабочий пример: Expo Snack
Чтобы узнать больше, numcolumns