# React Native [![Build Status](https://travis-ci.org/facebook/react-native.svg?branch=master)](https://travis-ci.org/facebook/react-native)
React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and
[React](http://facebook.github.io/react). The focus of React Native is on developer efficiency across all the platforms you care about - learn once, write anywhere. Facebook uses React Native in multiple production apps and will continue investing in React Native.
## Native iOS Components
With React Native, you can use the standard platform components such as `UITabBar` and `UINavigationController` on iOS. This gives your app a consistent look and feel with the rest of the platform ecosystem, and keeps the quality bar high. These components are easily incorporated into your app using their React component counterparts, such as _TabBarIOS_ and _NavigatorIOS_.
```javascript
var React = require('react-native');
var { TabBarIOS, NavigatorIOS } = React;
var App = React.createClass({
render: function() {
return (
<TabBarIOS>
<TabBarIOS.Item title="React Native" selected={true}>
<NavigatorIOS initialRoute={{ title: 'React Native' }} />
</TabBarIOS.Item>
</TabBarIOS>
);
},
});
```
## Asynchronous Execution
All operations between the JavaScript application code and the native platform are performed asynchronously, and the native modules can also make use of additional threads as well. This means we can decode images off of the main thread, save to disk in the background, measure text and compute layouts without blocking the UI, and more. As a result, React Native apps are naturally fluid and responsive. The communication is also fully serializable, which allows us to leverage Chrome Developer Tools to debug the JavaScript while running the complete app, either in the simulator or on a physical device.
![](http://facebook.github.io/react-native/img/chrome_breakpoint.png)
## Touch Handling
iOS has a very powerful system called the Responder Chain to negotiate touches in complex view hierarchies which does not have a universal analog on the web. React Native implements a similar responder system and provides high level components such as TouchableHighlight that integrate properly with scroll views and other elements without any additional configuration.
```javascript
var React = require('react-native');
var { ScrollView, TouchableHighlight, Text } = React;
var TouchDemo = React.createClass({
render: function() {
return (
<ScrollView>
<TouchableHighlight onPress={() => console.log('pressed')}>
<Text>Proper Touch Handling</Text>
</TouchableHighlight>
</ScrollView>
);
},
});
```
## Flexbox and Styling
Laying out views should be easy, which is why we brought the flexbox layout model from the web to React Native. Flexbox makes it simple to build the most common UI layouts, such as stacked and nested boxes with margin and padding. React Native also supports common web styles, such as `fontWeight`, and the `StyleSheet` abstraction provides an optimized mechanism to declare all your styles and layout right along with the components that use them and apply them inline.
```javascript
var React = require('react-native');
var { Image, StyleSheet, Text, View } = React;
var ReactNative = React.createClass({
render: function() {
return (
<View style={styles.row}>
<Image
source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}}
style={styles.image}
/>
<View style={styles.text}>
<Text style={styles.title}>
React Native
</Text>
<Text style={styles.subtitle}>
Build high quality mobile apps using React
</Text>
</View>
</View>
);
},
});
var styles = StyleSheet.create({
row: { flexDirection: 'row', margin: 40 },
image: { width: 40, height: 40, marginRight: 10 },
text: { flex: 1, justifyContent: 'center'},
title: { fontSize: 11, fontWeight: 'bold' },
subtitle: { fontSize: 10 },
});
```
## Polyfills
React Native is focused on changing the way view code is written. For the rest, we look to the web for universal standards and polyfill those APIs where appropriate. You can use npm to install JavaScript libraries that work on top of the functionality baked into React Native, such as `XMLHttpRequest`, `window.requestAnimationFrame`, and `navigator.geolocation`. We are working on expanding the available APIs, and are excited for the Open Source community to contribute as well.
```javascript
var React = require('react-native');
var { Text } = React;
var GeoInfo = React.createClass({
getInitialState: function() {
return { position: 'unknown' };
},
componentDidMount: function() {
navigator.geolocation.getCurrentPosition(
(position) => this.setState({position}),
(error) => console.error(error)
);
},
render: function() {
return (
<Text>
Position: {JSON.stringify(this.state.position)}
</Text>
);
},
});
```
## Extensibility
It is certainly possible to create a great app using React Native without writing a single line of native code, but React Native is also designed to be easily extended with custom native views and modules - that means you can reuse anything you've already built, and can import and use your favorite native libraries. To create a simple module in iOS, create a new class that implements the `RCTBridgeModule` protocol, and add `RCT_EXPORT` to the function you want to make available in JavaScript.
```objc
// Objective-C
#import "RCTBridgeModule.h"
@interface MyCustomModule : NSObject <RCTBridgeModule>
@end
@implementation MyCustomModule
- (void)processString:(NSString *)input callback:(RCTResponseSenderBlock)callback
{
RCT_EXPORT(); // available as NativeModules.MyCustomModule.processString
callback(@[[input stringByReplacingOccurrencesOfString:@"Goodbye" withString:@"Hello"]]);
}
@end
```
```javascript
// JavaScript
var React = require('react-native');
var { NativeModules, Text } = React;
var Message = React.createClass({
getInitialState() {
return { text: 'Goodbye World.' };
},
componentDidMount() {
NativeModules.MyCustomModule.processString(this.state.text, (text) => {
this.setState({text});
});
},
render: function() {
return (
<Text>{this.state.text}</Text>
);
},
});
```
Custom iOS views can be exposed by subclassing `RCTViewManager`, implementing a `-view` method, and exporting properties with the `RCT_EXPORT_VIEW_PROPERTY` macro. Then a simple JavaScript file connects the dots.
```objc
// Objective-C
#import "RCTViewManager.h"
@interface MyCustomViewManager : RCTViewManager
@end
@implementation MyCustomViewManager
- (UIView *)view
{
return [[MyCustomView alloc] init];
}
RCT_EXPORT_VIEW_PROPERTY(myCustomProperty);
@end
```
```javascript
// JavaScript
var MyCustomView = createReactIOSNativeComponentClass({
validAttributes: { myCustomProperty: true },
uiViewClassName: 'MyCustomView',
});
```
## Running the Examples
- `git clone git@github.com:facebook/react-native.git`
- `cd react-native && npm install`
- `cd Examples`
Now open any example and hit run in Xcode.
Further documentation, tutorials, and more on the [React Native website](http://facebook.github.io/react-native/docs/getting-started.html).
## 仓库
https://github.com/facebook/react-native
没有合适的资源?快使用搜索试试~ 我知道了~
react-native-0.3.5.zip
共686个文件
js:340个
h:99个
m:96个
需积分: 0 0 下载量 140 浏览量
2024-08-29
15:43:48
上传
评论
收藏 4.09MB ZIP 举报
温馨提示
一个使用 React 构建 app 应用程序的框架 A framework for building native applications using React
资源推荐
资源详情
资源评论
收起资源包目录
react-native-0.3.5.zip (686个子文件)
launchChromeDevTools.applescript 1KB
Layout.c 30KB
launchPackager.command 485B
react-native.css 14KB
index.css 2KB
.eslintignore 54B
.eslintrc 14KB
.flowconfig 805B
.gitignore 335B
.gitignore 274B
.gitignore 42B
RCTConvert.h 7KB
RCTViewManager.h 7KB
FBSnapshotTestController.h 6KB
RCTShadowView.h 6KB
FBSnapshotTestCase.h 5KB
RCTLog.h 4KB
SRWebSocket.h 4KB
Layout.h 4KB
RCTBridge.h 3KB
RCTTestRunner.h 3KB
RCTRootView.h 3KB
RCTBridgeModule.h 2KB
RCTView.h 2KB
RCTEventDispatcher.h 2KB
RCTUtils.h 2KB
RCTUIManager.h 2KB
RCTScrollView.h 2KB
RCTImageDownloader.h 2KB
RCTAssert.h 2KB
RCTWebViewExecutor.h 1KB
RCTJavaScriptExecutor.h 1KB
RCTShadowText.h 1KB
UIImage+Compare.h 1KB
UIImage+Diff.h 1KB
RCTNetworkImageView.h 1KB
RCTSparseArray.h 1KB
RCTViewNodeProtocol.h 1KB
RCTAsyncLocalStorage.h 1KB
UIView+React.h 1KB
RCTWrapperViewController.h 1KB
RCTJSMethodRegistrar.h 1KB
RCTNavigator.h 1KB
RCTKeyCommands.h 977B
RCTContextExecutor.h 881B
RCTMap.h 860B
RCTTestModule.h 844B
RCTCache.h 816B
RCTPushNotificationManager.h 808B
RCTScrollableProtocol.h 805B
RCTWebView.h 784B
RCTViewControllerProtocol.h 773B
AppDelegate.h 769B
AppDelegate.h 769B
AppDelegate.h 768B
AppDelegate.h 768B
RCTRedBox.h 733B
RCTJavaScriptLoader.h 702B
RCTExceptionsManager.h 687B
RCTNavItem.h 681B
RCTTextField.h 667B
RCTTouchHandler.h 621B
RCTText.h 616B
RCTInvalidating.h 614B
RCTPicker.h 611B
RCTAutoInsetsProtocol.h 593B
RCTLinkingManager.h 591B
RCTImageLoader.h 568B
RCTGIFImage.h 550B
RCTTabBarItem.h 539B
RCTAnimationType.h 537B
RCTSourceCode.h 531B
RCTReachability.h 527B
RCTPointerEvents.h 519B
RCTTabBar.h 505B
RCTStaticImage.h 502B
RCTAnimationExperimentalManager.h 486B
RCTDevMenu.h 486B
RCTTiming.h 475B
RCTWebSocketExecutor.h 461B
AppDelegate.h 452B
AppDelegate.h 451B
RCTAdSupport.h 441B
RCTDataManager.h 436B
RCTShadowRawText.h 432B
RCTStatusBarManager.h 430B
RCTActionSheetManager.h 426B
RCTAlertManager.h 426B
RCTSwitch.h 417B
RCTCameraRollManager.h 406B
RCTUIActivityIndicatorViewManager.h 406B
RCTLocationObserver.h 404B
RCTNetworkImageViewManager.h 400B
RCTVibration.h 398B
RCTAppState.h 396B
RCTStaticImageManager.h 394B
RCTScrollViewManager.h 394B
RCTNavigatorManager.h 393B
RCTTabBarItemManager.h 393B
RCTTextFieldManager.h 393B
共 686 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
a3737337
- 粉丝: 0
- 资源: 2869
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- STT3599C-VB一种2个N+P-Channel沟道SOT23-6封装MOS管
- 7-1.PWM驱动LED呼吸灯 keilC语言代码
- STT3585-VB一种2个N+P-Channel沟道SOT23-6封装MOS管
- 2024年省市县三级行政区划数据(审图号:GS(2024)0650号).zip
- STT3520C-VB一种2个N+P-Channel沟道SOT23-6封装MOS管
- python《基于轻量化重构网络的表面缺陷视觉检测》+项目源码+文档说明
- STT3463P-VB一种P-Channel沟道SOT23-6封装MOS管
- [2024版]03.实验三:创建更多内容的网站.doc
- C++项目:基于C++语言实现的坦克大战游戏源代码(含exe可执行文件),分享给需要的同学
- STT3434-VB一种N-Channel沟道SOT23-6封装MOS管
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功