Вы можете установить «npm install response-native-super-grid» и попробовать это.Вы можете изменить itemDimension, тогда он изменит количество значков, которые должны отображаться на экране.Это только пример, который вы можете изменить, когда вам нужно.
import React, { Component } from "react";
import {
StyleSheet,
View,
Text,
TouchableOpacity,
PixelRatio,
Image
} from "react-native";
import { Container, Header, Content } from "native-base";
import GridView from "react-native-super-grid";
const buttons = [
{
name: "test1",
image: require("./src/icons/test1.png"),
key: 1
},
{
name: "test2",
image: require("./src/icons/test2.png"),
key: 2
},
{
name: "test3",
image: require("./src/icons/test3.png"),
key: 3
},
{
name: "test4",
image: require("./src/icons/test4.png"),
key: 4
},
];
class Home extends Component {
constructor(props) {
super(props);
}
onPress(){
}
render() {
return (
<Container style={styles.container}>
<Content contentContainerStyle={styles.contentContainerStyle}>
<GridView
itemDimension={180}
items={buttons}
renderItem={item => (
<View style={styles.gridCompenentContainer}>
<TouchableOpacity
onPress={this.onPress.bind(this)}
activeOpacity={0.8}
style={styles.touchView}
>
<Image
style={{ width: 60, height: 60 }}
source={item.image}
/>
</TouchableOpacity>
<View style={styles.textView}>
<Text style={styles.text}>{item.name} </Text>
</View>
</View>
)}
/>
</Content>
</Container>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#fff"
},
contentContainerStyle: {
backgroundColor: "#fff",
justifyContent: "center"
},
gridCompenentContainer: {
width: 160,
height: 140,
flexDirection: "column",
justifyContent: "center",
alignItems: "center"
},
touchView: {
width: 80,
justifyContent: "center",
alignItems: "center",
height: 80,
borderRadius: 40,
backgroundColor: "#0099cc"
},
textView: {
width: 140,
height: 50,
justifyContent: "center",
alignItems: "center"
},
text: {
width: 140,
fontSize: 12,
textAlign: "center",
color: "#0099cc"
}
});
export default Home;