react-native试玩(4)-新建项目
发布时间:2020-12-15 05:22:28 所属栏目:百科 来源:网络整理
导读:源码 /** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict' ; var React = require( 'react-native' ); var { AppRegistry,StyleSheet,Text,View,} = React; var helloworld = React.createClass({ render: function(
源码/** * Sample React Native App * https://github.com/facebook/react-native */
'use strict';
var React = require('react-native');
var {
AppRegistry,StyleSheet,Text,View,} = React;
var helloworld = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started,edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},welcome: {
fontSize: 20,textAlign: 'center',margin: 10,instructions: {
textAlign: 'center',color: '#333333',marginBottom: 5,});
AppRegistry.registerComponent('hellowrold',() => helloworld);
问题
总结新建项目分5步: 引入react-nativevar React = require('react-native');
定义组件var { AppRegistry,} = React;
定义界面控件var helloworld = React.createClass({});
定义控件样式var styles = StyleSheet.create({});
为项目注册界面AppRegistry.registerComponent('项目名',() =>界面);
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |