非常教程

React native参考手册

指南 | Guides

JavaScript Environment

JavaScript运行时

使用React Native时,您将在两种环境中运行JavaScript代码:

  • 在iOS模拟器和设备上,Android模拟器和设备React Native使用JavaScriptCore,它是支持Safari的JavaScript引擎。在iOS上由于iOS应用程序中缺少可写的可执行内存,JSC不使用JIT。
  • 使用Chrome调试时,它会在Chrome本身内运行所有JavaScript代码,并通过WebSocket与本机代码进行通信。所以你正在使用V8。

虽然这两种环境非常相似,但最终可能会遇到一些不一致之处。我们很可能会在未来尝试其他JS引擎,所以最好避免依赖任何运行时的细节。

JavaScript语法变形金刚

语法转换器使编写代码更加愉快,让您可以使用新的JavaScript语法,而无需等待所有解释器的支持。

从版本0.5.0开始,React Native随附Babel JavaScript编译器。查看Babel关于其支持的转换的文档以获取更多详细信息。

以下是React Native已启用转换的完整列表。

ES5

  • 保留字:promise.catch(function() { });ES6
  • Arrow functions: <C onPress={() => this.setState({pressed: true})}
  • Block scoping: let greeting = 'hi';
  • Call spread: Math.max(...array);
  • Classes: class C extends React.Component { render() { return <View />; } }
  • Constants: const answer = 42;
  • Destructuring: var {isActive, style} = this.props;
  • for...of: for (var num of [1, 2, 3]) {}
  • Modules: import React, { Component } from 'react';
  • Computed Properties: var key = 'abc'; var obj = {[key]: 10};
  • Object Concise Method: var obj = { method() { return 10; } };
  • Object Short Notation: var name = 'vjeux'; var obj = { name };
  • Rest Params: function(type, ...args) { }
  • Template Literals: var who = 'world'; var str = `Hello ${who}`;

ES7

  • Object Spread: var extended = { ...obj, a: 10 };
  • Function Trailing Comma: function f(a, b, c,) { }
  • Async Functions: async function doStuffAsync() { const foo = await doOtherStuffAsync(); };

Specific

  • JSX: <View style={{color: 'red'}} />
  • Flow: function foo(x: ?number): string {}

Polyfills

许多标准函数也可用于所有支持的JavaScript运行时。

浏览器

  • console.{log, warn, error, info, trace, table}
  • CommonJS require
  • XMLHttpRequest, fetch
  • {set,clear} {Timeout,Interval,Immediate},{request,cancel} AnimationFrame
  • navigator.geolocation

ES6

  • Object.assign
  • String.prototype.{startsWith, endsWith, repeat, includes}
  • Array.from
  • Array.prototype.{find, findIndex, includes}

ES7

  • Object.{entries, values}Specific
  • __DEV__
React native

React Native 是一个 JavaScript 的框架,用来撰写实时的、可原生呈现 iOS 和 Android 的应用。

主页 https://facebook.github.io/react-native/
源码 https://github.com/facebook/react-native
发布版本 0.49

React native目录

1.开始 | Getting Started
2.指南 | Guides
3.APIs
4.组件:ActivityIndicator | Components: ActivityIndicator
5.组件:按钮 | Components: Button
6.组件:CheckBox | Components: CheckBox
7.组件:DatePickerIOS | Components: DatePickerIOS
8.组件:DrawerLayoutAndroid | Components: DrawerLayoutAndroid
9.组件:FlatList | Components: FlatList
10.组件:图像 | Components: Image
11.组件:KeyboardAvoidingView | Components: KeyboardAvoidingView
12.Components: ListView
13.Components: MaskedViewIOS
14.Components: Modal
15.Components: NavigatorIOS
16.Components: Picker
17.Components: PickerIOS
18.Components: ProgressBarAndroid
19.Components: ProgressViewIOS
20.Components: RefreshControl
21.Components: ScrollView
22.Components: SectionList
23.Components: SegmentedControlIOS
24.Components: Slider
25.Components: SnapshotViewIOS
26.Components: StatusBar
27.Components: Switch
28.Components: TabBarIOS
29.Components: TabBarIOS.Item
30.Components: Text
31.Components: TextInput
32.Components: ToolbarAndroid
33.Components: TouchableHighlight
34.Components: TouchableNativeFeedback
35.Components: TouchableOpacity
36.Components: TouchableWithoutFeedback
37.Components: View
38.Components: ViewPagerAndroid
39.Components: VirtualizedList
40.Components: WebView
41.创建 | Contributing
42.指南(Android) | Guides (Android)
43.指南(IOS) | Guides (iOS)
44.其他 | Miscellaneous