【发布时间】:2017-10-02 22:10:04
【问题描述】:
我正在开发一个无限滚动的产品列表,其中包含不同类型的产品。产品可以有特色也可以没有特色。当产品被推荐时,我们的产品卡片设计会占据手机的整个宽度,否则设计需要 2 列行
数据看起来像这样:
[
{
"type": "featured-product",
"name": "Product",
"description: "yadda yadda"
},
{
"type": "product",
"name": "Another Product",
"description: "yadda yadda"
},
{
"type": "product",
"name": "And Another Product",
"description: "yadda yadda"
},
{
"type": "product",
"name": "One more Product",
"description: "yadda yadda"
}
{
"type": "product",
"name": "Yet another",
"description: "yadda yadda"
},
{
"type": "featured-product",
"name": "This one's Featured though",
"description: "yadda yadda"
}
]
例如,列表如下所示:
--------------
| |
| Featured |
| |
--------------
| || |
| Not || Not |
| || |
--------------
| || |
| Not || Not |
| || |
--------------
| |
| Featured |
| |
--------------
| || |
| Not || Not |
| || |
--------------
| || |
| Not || Not |
| || |
--------------
但是,使用FlatList 组件,我没有运气实现这个设计的布局。
- 为每个项目添加样式
flex: 1全宽和flex: 0.5双列不允许换行并始终显示单列行 - 将
numColumns属性设置为 2 可以稍微正确地显示产品,但会导致全宽特色项目出现问题。 - 考虑过将项目按 2 分块并让它们代表一个项目,但事实证明在使用 Flow 时需要更多开销
我一直在冒险使用 FlatList 以获得性能优势,但我开始认为它可能不适合我需要的布局。
以前有人解决过这个问题吗?
【问题讨论】:
-
你能发布你的
renderer代码来获取 FlatList 数据吗? -
如果您向我们提供呈现的标记,我们或许可以提出解决方案。
-
react-native-super-grid 以及@bennygenel 的回答可能对您有用。
标签: react-native flexbox react-native-android react-native-ios