Skip to main content

发布级别

React Native 为社区提供了在新功能的设计和实现接近完成时(甚至在它们被纳入稳定版本之前)立即采用它们的能力。这种方法被称为发布级别。

¥React Native provides the community with the ability to adopt individual new features as soon as their design and implementation are nearly complete, even before they are included in a stable release. This approach is known as release levels.

你可以配置 React Native 的发布级别,以便你的 React Native 实例在初始化时将功能标志设置为 EXPERIMENTALCANARYSTABLE 模式。

¥You can configure the release level of React Native so that your React Native instance will initialize with Feature Flags set to either EXPERIMENTAL, CANARY, or STABLE modes.

注意

这种方法与 React 中的 Canary 版本和实验版本 类似,但有一个关键区别:无论版本级别如何,都使用相同版本的 React JS 和 React Native 代码。React Native 也没有使用 @canary@experimental NPM 标签,因为 React Native 的稳定版和 Nightly 版都提供不同的发布级别。

¥This approach is similar to Canary and Experimental releases in React, but with a key difference: regardless of the release level, the same version of React JS and React Native code is used.\ React Native is also not using @canary or @experimental NPM tags, as release levels are available for both stable and nightly releases of React Native.

此外,将发布级别设置为 EXPERIMENTALCANARY 不会导致使用 react@nightlyreact@canary,因为 react-native 正在使用 React 版本 (你可以在此处阅读更多相关信息)。

¥Moreover, setting the release level to EXPERIMENTAL or CANARY will not result in consuming react@nightly or react@canary due to how react-native is consuming the React version (you can read more about it here).

何时使用每个版本级别

¥When to Use Each Release Level

  • STABLE

    • 适用于所有不需要提前访问未发布功能的生产应用和库。

      ¥Use for all production apps and libraries that do not need early access to unreleased features.

    • 这是稳定版和夜间版的默认级别。

      ¥This is the default level for stable and nightly releases.

  • CANARY

    • 如果你是框架作者、高级应用开发者,或者需要在新功能发布稳定版本之前进行测试或采用,请使用此渠道。

      ¥Use if you are a framework author, advanced app developer, or need to test or adopt new features before they are released in stable.

    • 不建议用于生产环境或面向用户的应用。

      ¥Not recommended for production or user-facing applications.

  • EXPERIMENTAL

    • 仅用于在开发早期阶段测试和提供新功能的反馈。

      ¥Use only for testing and providing feedback for new features in the early stages of development

    • 不建议用于生产环境或面向用户的应用。

      ¥Not recommended for production or user-facing applications.

如何使用 Canary 和实验版本初始化 React Native

¥How to initialize React Native using Canary & Experimental

安卓

¥Android

DefaultNewArchitectureEntryPoint 类现在具有 releaseLevel 属性(默认值:STABLE)。功能标志系统使用此属性为所选版本级别选择合适的功能标志集。

¥The DefaultNewArchitectureEntryPoint class now has a releaseLevel property (default: STABLE).\ The feature flag system uses this property to select the appropriate set of feature flags for the chosen release level.

Example usage
DefaultNewArchitectureEntryPoint.releaseLevel = ReleaseLevel.CANARY
DefaultNewArchitectureEntryPoint.load()

构建系统会为每个版本级别生成不同的功能标志覆盖类,以确保每个阶段都启用正确的功能。

¥The build system generates different feature flag override classes for each release level, ensuring the correct features are enabled for each stage.

iOS

RCTReactNativeFactory 类现在具有一个接受 releaseLevel 参数的初始化程序。功能标志设置使用此参数来选择正确的功能标志覆盖。

¥The RCTReactNativeFactory class now has an initializer that accepts a releaseLevel parameter. The feature flag setup uses this parameter to select the correct feature flag overrides.

Example usage
[[RCTReactNativeFactory alloc] initWithDelegate:delegate releaseLevel:Canary];

系统确保每个应用实例只有一个版本级别处于活动状态,如果创建多个具有不同版本级别的工厂,系统将崩溃。

¥The system ensures that only one release level is active per app instance, and will crash if multiple factories are created with different release levels.