【发布时间】:2020-12-02 12:37:29
【问题描述】:
我有带按钮的数组映射。现在我希望容器像现在一样(在中心)但是当新行未满时我希望项目开始(现在它也在中心) 我该如何处理?(见下图)
我的组件代码:
const AvailableHours = ({ avHoursInDay }) => {
return (
<View style={styles.container}>
{avHoursInDay.map((item, i) => {
return (
<TouchableOpacity key={i} style={styles.button} onPress={console.log("s")}>
<Text style={styles.text}>{item.time}</Text>
</TouchableOpacity>
);
})}
</View>
);
} ;
const styles = StyleSheet.create({
container: {
flexDirection: "row",
flexWrap: "wrap",
justifyContent: "center",
borderWidth: 1,
borderColor: "red",
},
text: {
color: "white",
paddingHorizontal: 15,
paddingVertical: 6,
fontSize: 16,
fontFamily: "heebo",
textAlign: "center",
},
button: {
margin: 2,
borderRadius: 12,
borderWidth: 1,
backgroundColor: "transparent",
borderColor: "#d9b310",
},
【问题讨论】:
标签: javascript css react-native