跳到主要内容
新架构实战课 实操 + 基建 + 原理全维度包揽,抢先掌握 React Native 新架构精髓 立即查看 >

新架构的“两驾马车”

注意

本文档内容仍处于实验阶段,内容会随着版本的迭代进行修改。您可随时在我们的工作组的讨论区发送反馈。 此外,本文档还包含了若干需手动配置的步骤,但这不代表新架构稳定版的最终开发体验。我们仍在开发相关的工具、模板和第三方库,帮助你更快地迁移到新架构上,而非从头开始配置环境。

The New Architecture is composed mainly by two pillars:

TurboModules are the preferred way to create libraries that leverage some platform specific API. Fabric 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 TurboModule or Fabric Component.

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

  1. Define a JavaScript specification using Flow or TypeScript.
  2. Configure the dependencies management system to generate code from the provided spec.
  3. Implement the Native code.
  4. Integrate the code in the app.

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.

caution

To integrate a TurboModule or a Fabric Component in an app, the app has to run with the New Architecture enabled.

To create a new app adopting the New Architecture, refer to the Using the App Template section. To migrate an existing app to the New Architecture, refer to the Migration guide.