Last active
August 29, 2015 14:22
-
-
Save sherlock221/7f55e35ed536f51dc7ce to your computer and use it in GitHub Desktop.
基本的ListView组件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 基本的listiew | |
* sherlock221b | |
*/ | |
'use strict'; | |
var React = require('react-native'); | |
var { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View, | |
Image, | |
ListView, | |
NavigatorIOS, | |
TextInput, | |
TouchableHighlight | |
} = React; | |
var uk = React.createClass({ | |
getInitialState: function() { | |
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | |
return { | |
dataSource: ds.cloneWithRows([{"name" : "小明","age":10}, {"name" : "小红","age":30}]) | |
}; | |
}, | |
renderRow : function(rowData, sectionID, rowID){ | |
return ( | |
<View style={css.row}> | |
<Text style={css.text}>{rowData.name}</Text> | |
<Text style={css.text}>{rowData.age}</Text> | |
</View> | |
); | |
}, | |
render: function() { | |
return ( | |
<ListView style={css.container} dataSource={this.state.dataSource} | |
renderRow={this.renderRow.bind(this)}/> | |
); | |
} | |
}); | |
var css = StyleSheet.create({ | |
container: { | |
marginTop : 35, | |
padding : 20 | |
}, | |
row : { | |
flexDirection : "row", | |
paddingBottom : 10, | |
borderBottomWidth : 1, | |
borderColor : '#ccc', | |
marginBottom : 10 | |
}, | |
text : { | |
flex : 1 | |
} | |
}); | |
AppRegistry.registerComponent('uk', () => uk); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment