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

What Backward Compatibility Is

注意

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

Creating a backward compatible module is important to provide a library that works in both the Old Architecture and the New Architecture. Not all the users of your library will immediately jump on the New Architecture ship: it is a good thing that they will be able to use your library even if they are still using the old architecture.

The trick to create a good backward compatible module is to minimize the changes required to adopt the new version. In that way, users of the module can smoothly move to the new version and migrate to the New Architecture when they are ready, ideally by issueing one different command.

To achieve this result, we have to perform few changes in our TurboModule and Fabric Component configurations. The steps we have to follow are:

  1. Update the installation configuration to avoid using code that is not needed by the Old Architecture.
  2. Update the code to support both architectures. Both Android and iOS build pipelines gives you mechanism to provide a library that will compile with the correct React Native Architecture.
  3. Configure the specs to load the proper implementation, so that the JavaScript layer leverages the New Architecture whan it is available.
info

The next sections requires that you are familiar with the Pillars of the New Architecture.

  • To create a backward compatible TurboModule, follow this guide.
  • To create a backward compatible Fabric Component, follow this guide.