标签:0kb cdt xtu i2c text smd 12c abc ccm
index.android.js文件 import React, { … … } from ‘react-native‘; class AwesomeProject extends Component { render() { return ( <View> //全部核心组件都能够接受style属性 <Text style={styles.base}>Declare Style</Text> //接受数组形式的多个style <Text style={[styles.base, styles.background]}>Declare Style</Text> //依据某些条件选择性的加入样式。否定型取值如false,undefined和null则会被忽略 <View style={[styles.base, true && styles.active]}/> //能够在render方法中创建样式,多个值冲突的时候,右边的元素优先级最高 <View style={[styles.background, styles.base, { width:80, height:80}]}/> </View> ); } } //声明样式 var styles = StyleSheet.create({ base: { width: 100, height: 38, }, background: { backgroundColor: ‘#cccccc‘, }, active: { borderWidth: 2, borderColor: ‘#00ff00‘, }, }); AppRegistry.registerComponent(‘AwesomeProject‘, () => AwesomeProject);
index.android.js文件: import React, { … … } from ‘react-native‘; class AwesomeProject extends Component { render() { return ( <View style={styles.flexcontain}> <View style={styles.flexitem}> <Text>1</Text> </View> <View style={styles.flexitem}> <Text>2</Text> </View> <View style={styles.flexitem}> <Text>3</Text> </View> <View style={styles.flexitem}> <Text>4</Text> </View> <View style={[styles.flexitem,styles.item5]}> <Text>5</Text> </View> </View> ); } } var styles = StyleSheet.create({ flexcontain: { width:300, height:300, borderWidth:1, borderColor:‘blue‘, flexDirection:‘row‘, top:100, left:100, }, flexitem: { width:50, height:50, borderWidth:1, borderColor:‘white‘, backgroundColor:‘gray‘, justifyContent:‘center‘, alignItems:‘center‘, }, item5: { alignSelf:‘stretch‘, }, }); AppRegistry.registerComponent(‘AwesomeProject‘, () => AwesomeProject);
import React, { AppRegistry, … … } from ‘react-native‘; //创建List组件 var List = React.createClass({ //声明传递參数和參数类型 propTypes: { style: View.propTypes.style, elementStyle: View.propTypes.style, }, render() { var elements = [‘element1‘,‘element2‘,‘element3‘]; return ( //使用參数传递过来的样式设置子组件 <View style={this.props.style}> //直接调用和使用參数传递的样式设置子组件 {elements.map((element) =><View key={element} style={[styles.element, this.props.elementStyle]} />)} </View> ); } }); class AwesomeProject extends Component { render() { return ( <View> <List style={styles.list} elementStyle={styles.listElement} /> </View> ); } } var styles = StyleSheet.create({ //传递给子组件样式list list: { width:300, height:300, borderWidth:1, borderColor:‘blue‘, }, //传递给子组件样式listElement listElement: { width:50, height:50, backgroundColor:‘gray‘, }, //直接调用样式element element: { borderWidth:1, borderColor:‘yellow‘, } }); AppRegistry.registerComponent(‘AwesomeProject‘, () => AwesomeProject
标签:0kb cdt xtu i2c text smd 12c abc ccm
原文地址:http://www.cnblogs.com/clnchanpin/p/7229961.html