【发布时间】:2017-03-18 00:41:01
【问题描述】:
我正在学习本机反应,在所有教程中,我看到 ListView 每行仅使用 1 个项目。不过,我没有使用过 ListView。我只有 6 个项目必须显示为平面网格,每行 2 个项目并且应该是响应式的。我知道这是一个基本问题,但我也从我身边尝试过,这可以在图片中看到
这是我的代码
renderDeviceEventList() {
return _.map(this.props.deviceEventOptions, deviceEventOption => (
<View key={deviceEventOption.id}>
<Icon
name={deviceEventOption.icon_name}
color="#ddd"
size={30}
onPress={() =>
this.props.selectDeviceEvent(deviceEventOption)
}
/>
<Text style={{ color: "#ff4c4c" }}>
{deviceEventOption.icon_name}
</Text>
</View>
));
}
render() {
return (
<View
style={{
flex: 1,
top: 60,
flexDirection: "row",
justifyContent: "space-around",
flexWrap: "wrap",
marginBottom: 10
}}
>
{this.renderDeviceEventList()}
</View>
);
}
【问题讨论】:
-
当我在 renderDeviceEventList 中为 View 组件提供宽度和高度时,它可以工作但没有响应。我知道有一个 Dimension 库,但我听说它在更改方向时不起作用。
标签: javascript reactjs react-native flexbox