非常教程

React native参考手册

指南 | Guides

Upgrading to new React Native versions

升级到React Native的新版本可让您访问更多的API,视图,开发人员工具和其他好东西。升级需要少量的努力,但我们试图让你更容易。这些说明有点不同,具体取决于您是使用create-react-native-appreact-native init创建项目。

创建 React Native App 项目

升级您创建阵营原生应用项目反应本土的新版本需要更新react-nativereact以及expo在你的包版本package.json的文件。请参阅此文档以了解哪些版本受支持。您还需要sdkVersionapp.json文件中设置正确的值。

有关升级项目的最新信息,请参阅CRNA用户指南。

使用本机代码构建的项目

只有原生代码的项目

本部分仅适用于react-native init使用Create React Native App创建的项目或已经退出的项目。有关弹出的更多信息,请参阅创建React Native App存储库的指南。

由于使用本机代码构建的React Native项目基本上由Android项目,iOS项目和JavaScript项目组成,因此升级可能非常棘手。以下是从旧版本的React Native进行升级所需执行的操作。

基于Git升级

该模块react-native-git-upgrade提供一步操作,以最少的冲突升级源文件。在引擎盖下,它分为两个阶段:

  • 首先,它计算旧的和新的模板文件之间的Git补丁,
  • 然后,修补程序将应用于用户的来源。

重要提示:您不必安装新版本的react-native软件包,它会自动安装。

1.安装Git

虽然您的项目不必由Git版本控制系统处理 - 您可以使用Mercurial,SVN或者什么都不用 - 您仍然需要在系统上安装Git才能使用react-native-git-upgrade。Git也需要可用PATH

2.安装react-native-git-upgrade模块

react-native-git-upgrade模块提供了一个CLI,并且必须全局安装:

$ npm install -g react-native-git-upgrade

3.运行命令

运行以下命令启动升级到最新版本的过程:

$ react-native-git-upgrade

您可以通过传递参数来指定React Native版本: react-native-git-upgrade X.Y

模板以优化的方式升级。您仍然可能会遇到冲突,但仅限于Git 3-way合并失败的情况,具体取决于版本以及您如何修改源代码。

4.解决冲突

冲突的文件包括分隔符,这些分隔符非常清楚变化的来源。例如:

13B07F951A680F5B00A75B9A /* Release */ = {
  isa = XCBuildConfiguration;
  buildSettings = {
    ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
<<<<<<< ours
    CODE_SIGN_IDENTITY = "iPhone Developer";
    FRAMEWORK_SEARCH_PATHS = (
      "$(inherited)",
      "$(PROJECT_DIR)/HockeySDK.embeddedframework",
      "$(PROJECT_DIR)/HockeySDK-iOS/HockeySDK.embeddedframework",
    );
=======
    CURRENT_PROJECT_VERSION = 1;
>>>>>>> theirs
    HEADER_SEARCH_PATHS = (
      "$(inherited)",
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
      "$(SRCROOT)/../node_modules/react-native/React/**",
      "$(SRCROOT)/../node_modules/react-native-code-push/ios/CodePush/**",
    );

您可以将“我们的”视为“您的团队”,将他们的视为“React Native开发团队”。

替代

只有在上述情况不起作用的情况下,才使用它。

1.升级react-native依赖关系

从这里注意最新版本的react-nativenpm包(或者用于检查)。npm info react-native

现在react-native在您的项目中使用npm install --save以下版本安装该版本:

$ npm install --save react-native@X.Y
# where X.Y is the semantic version you are upgrading to
npm WARN peerDependencies The peer dependency react@~R included from react-native...

如果您看到有关peerDependency的警告,也可以react通过运行升级:

$ npm install --save react@R
# where R is the new version of react from the peerDependency warning you saw

2.升级您的项目模板

新的npm软件包可能包含运行时通常生成的文件的更新react-native init,例如iOS和Android子项目。

您可以咨询rn-diff以查看项目模板文件中是否有更改。如果没有,只需重建项目并继续开发。如果发生细微变化,您可以手动更新您的项目并重建。

如果发生重大变化,请在终端中运行以获取以下信息:

$ react-native upgrade

这将检查您的文件对照最新的模板并执行以下操作:

  • 如果模板中有新文件,则只需创建它。
  • 如果模板中的文件与您的文件相同,则会跳过该文件。
  • 如果项目中的文件与模板不同,则会提示您; 您可以选择保留文件或使用模板版本覆盖文件。

手动升级

某些升级需要手动步骤,例如0.13至0.14或0.28至0.29。请务必在升级时检查发行说明,以便确定您的特定项目可能需要的任何手动更改。

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