【Facebook的UI开发框架React入门之四】index.ios.js解读(iOS平台)-goodmao
来源:互联网 发布:数据仓库软件有哪些 编辑:程序博客网 时间:2024/06/05 11:53
参考:
https://facebook.github.io/react-native/docs/getting-started.html
https://facebook.github.io/react-native/docs/tutorial.html#content
最新版本的React库源码:react-native v0.5
https://github.com/facebook/react-native/releases/tag/v0.5.0-rc
---------------------------------------------------------------------------------------------------
React.native是facebook开源的一套基于JavaScript的开源框架,
很方便用来开发移动设备的app。
而且,方便及时更新app的UI与数据,也很方便部署。
goodmao希望帮助大家迅速上手掌握!
---------------------------------------------------------------------------------------------------
在第三节,我们创建的基于React.native的iOS项目中,
界面部分是一个js文件:index.ios.js
我们需要简单了解一下它的内容和各部分的作用,以便后续开发。
下面,我们解读一下该文件:
1.设置模式
'use strict';
这行代码'use strict';
作用:开启 Strict Mode,
Strict mode模式下,提高了错误处理能力,
也可以避免一些JavaScript的语言缺陷。
也就是:JavaScript在这种模式下可以更好地执行!
注意:Strict Mode介绍,详见Jon Resig 的文章:“ECMAScript 5 Strict Mode, JSON, and More”
2.导入React.native库
var React = require('react-native');
作用:加载 React-native 库,并将它赋值给变量 React。
React Native模块加载方式,和 Node.js 相同,都使用:require。
作用相当于 Swift 中的“链接库”或者“导入库”。
3.声明变量
var { AppRegistry, StyleSheet, Text, View,} = React;
4.定义文本样式
var styles = StyleSheet.create({ container: {//定义 View 视图的样式 flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: {//定义 Text 的样式 fontSize: 20, textAlign: 'center', margin: 10, }, instructions: {//定义 Text 的样式 textAlign: 'center', color: '#333333', marginBottom: 5, },});作用:定义了一段应用在 “Hello World” 文本上的样式。
React Native 使用CSS 来定义应用界面的样式。
5.创建React组件对应的类
var HelloReact = 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> ); }});
作用:描述将要创建的组件,包括各种行为和属性。
分析:
a.创建组件HelloReact的方法createClass( )
var HelloReact = React.createClass();
b.组件渲染的方法
render: function() {//渲染的方法 return ();}
注意:只有当组件被渲染时,必须实现render接口方法,
因为,只有render方法,是用于输出内容组件内容的;
其他接口方法,都是可选的。
c.标签<View>定义了视图
作用:设置显示区域,相当于iOS中的UIView控件(Objective-c和Swift)
<View style={styles.container}> //视图 View</View>
d.标签<Text>定义了文本
作用:设置并显示字符串,相当于iOS的UILabel控件(Objective-c和Swift)。
<Text style={styles.welcome}> //文本 Text Welcome to React Native!</Text>
6.定义程序入口
AppRegistry.registerComponent('HelloReact', () => HelloReact);
作用:用AppRegistry的registerComponent( )方法,定义了App的入口,并提供了根组件。
0 0
- 【Facebook的UI开发框架React入门之四】index.ios.js解读(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之二】开发环境搭建(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之三】第一个项目(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之九】按钮简介(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之八】Image的使用简介(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之五】视图View与文本Text简介(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之七】多View布局与样式Style简介(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之六】单个View的布局与样式Style简介(iOS平台)-goodmao
- 【Facebook的UI开发框架React入门之一】简介-goodmao
- React-Native 之index.ios.js解读
- IOS开发UI进阶之UITableView四
- Facebook 颠覆式前端 UI 开发框架 —— React
- ios中用JS 实现 Facebook 框架
- IOS 入门开发之分页栏TabBar的使用(四)
- Facebook 开发 的 几个步骤 (ios)
- UI第一章iOS开发入门
- Facebook React Native开发入门
- [React Native混合开发]React Native for iOS之CSS和UI布局
- NuPIC:一个开源的人工智能平台
- php 事务
- eclipse查看Android系统源代码
- Linux下*.tar.gz文件解压缩命令
- 【Unity】Unity Mesh 网格合并
- 【Facebook的UI开发框架React入门之四】index.ios.js解读(iOS平台)-goodmao
- cat >file,cat <file <<EOF,ls -l >file <<EOF
- c++中的 extern "C"用法
- swift 字符串,数组,字典 的那些事<三>
- Bootstrap3的栅格化样式
- Jquery分步指引给件
- Codeforces Round #292 (Div. 2) -- A. Drazil and Date
- 类和结构体一
- 梯度下降与逻辑回归