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:
- Update the installation configuration to avoid using code that is not needed by the Old Architecture.
- 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.
- Configure the specs to load the proper implementation, so that the JavaScript layer leverages the New Architecture whan it is available.
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.