Skip to main content

新架构由什么组成


提醒

本文档仍为 experimental,详细信息可能会随着我们的迭代而发生变化。 欢迎在此页面分享你对 工作组内部讨论 的反馈。

This documentation is still experimental and details are subject to changes as we iterate. Feel free to share your feedback on the discussion inside the working group for this page.

而且,它还包含几个 手动步骤。 请注意,一旦新架构稳定,这将不代表最终的开发者体验。 我们正在开发工具、模板和库,以帮助你快速开始使用新架构,而无需完成整个设置。

Moreover, it contains several manual steps. Please note that this won't be representative of the final developer experience once the New Architecture is stable. We're working on tools, templates and libraries to help you get started fast on the New Architecture, without having to go through the whole setup.

新架构主要由两大支柱组成:

The New Architecture is composed mainly of two pillars:

React Native 的核心概念在新架构中仍然适用: 原生模块是创建利用某些特定于平台的 API 的库的首选方式。 原生组件是创建可重用 UI 组件的首选方式,为用户提供原生体验。

The core concepts of React Native still holds true in the New Architecture: Native Modules are the preferred way to create libraries that leverage some platform-specific API. Native Components are the preferred way to create reusable UI components, providing a native experience to the users.

本节的主要目标是通过分步指南引导读者创建他们的第一个与新架构兼容的原生模块或组件。

The main goal of this section is to drive the reader through a step-by-step guide to create their first Native Module or Component which is compatible with the New Architecture.

信息

为了本指南的目的,我们将使用以下 terminology

For the sake of this guide we're going to use the following terminology:

  • 旧版的原生组件旧版原生模块 - 指在旧的 React Native 架构上运行的模块和组件。
  • Fabric 原生组件Turbo Native 模块 - 指已适应新架构的模块和组件,即新的渲染器和新的原生模块系统。 为了简洁起见,你可能会发现它们被称为 Fabric 组件涡轮增压模块

接下来的部分包含对支柱的高级概述以及创建它们的步骤。 要创建这些支柱之一,步骤如下:

The next sections contain a high-level overview of the pillars and the steps to create them. To create one of these pillars, the steps are:

  1. 使用 Flow 或 TypeScript 定义 JavaScript 规范。
  2. 配置依赖管理系统以根据提供的规范生成代码。
  3. 实现原生代码。
  4. 将代码集成到应用中。

最后,我们更深入地了解创建组件使用的所有 C++ 类型和文件所需的 代码生成器 过程,包括一些在开发组件时舒适工作的有用步骤。

Finally, we dive a little deeper into the Codegen process that is required to create all the C++ types and files used by our components, including some useful steps to work comfortably while developing the component.

提醒

该应用必须与应用中的 新架构能够集成 Turbo Native 模块或 Fabric Native 组件 一起运行。

The app has to run with the New Architecture enabled to integrate a Turbo Native Module or a Fabric Native Component in an app.

要创建采用新架构的新应用,请参阅 使用应用模板 部分。 要将现有应用迁移到新架构,请参阅 迁移 指南。