项目
在 GitHub 查看 Setup the
yelled3/react-native-grid-example
关于
React Native - Grid Layout Example
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文React Native - Grid Layout Example

By default React Native's ListView renders as a table.
In order to change the table layout to a grid layout (similar to UICollectionViewFlowLayout) you need to do the following;
Setup the ListView container style
A ListView root element is a ScrollView that inherits the ListView's props:
var ListView = React.createClass({
// ...
render: function() {
return (
<ScrollView {...props}
ref={SCROLLVIEW_REF}>
{header}
{bodyComponents}
{footer}
</ScrollView>
);
}
}
see source
With that in mind you can use the ScrollView's contentContainerStyle prop to style the ListView;
var GridLayoutExample = React.createClass({
// ...
render: function() {
return (
<ListView contentContainerStyle={styles.list}
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text style={styles.item}>{rowData}</Text>}
/>
);
}
Define the grid layout using flexbox
Using basic flexbox we can define whatever grid layout we want;
var styles = StyleSheet.create({
list: {
justifyContent: 'center',
flexDirection: 'row',
flexWrap: 'wrap'
},
item: {
backgroundColor: '#CCC',
margin: 10,
width: 100,
height: 100
}
});
If your flexbox is somewhat rusty, I highly recommend you go through this guide
Credits & References
- This example was based on Colin Ramsay's suggestion on StackoverFlow
- This is a follow up on the discussion started on https://github.com/facebook/react-native/issues/1276
- The example code was based on ListView example, included in the ReactNative's
UIExplorerexamples.
探索相关项目
加载中…