Skip to main content
Version: 6.x

俯仰和反俯仰

当考虑是否使用项目时,了解项目开发者在构建项目时所做的权衡非常有用。它明确试图为你解决哪些问题,又忽略了哪些问题?该项目目前的局限性和人们遇到的常见问题是什么?我们相信你在为你的项目做出重要技术决策时应该得到这些问题的答案,因此我们在这里尽可能以 "pitch" 的形式记录了这些问题的答案(为什么你应该使用它)和 "anti-pitch"(为什么你不应该使用它)。如果你认为我们遗漏了重要信息,请 提交拉取请求

¥It's useful when considering whether or not to use a project to understand the tradeoffs that the developers of the project made when building it. What problems does it explicitly try to solve for you, and which ones does it ignore? What are the current limitations of the project and common problems that people encounter? These are the kinds of questions that we believe you should have answers to when making an important technology decision for your project, and so we have documented answers to these questions as best we can here, in the form of a "pitch" (why you should use it) and "anti-pitch" (why you should not use it). Please submit a pull request if you believe we have omitted important information!

沥青

¥Pitch

  • React Navigation 库本身不包含任何原生代码,但我们使用许多原生库(例如 屏幕复活手势处理程序 等)来实现高性能动画和手势。根据导航器的不同,许多 UI 组件都是在 React Native 原语之上用 JavaScript 编写的。这有很多好处:

    ¥React Navigation doesn't include any native code in the library itself, but we use many native libraries such as Screens, Reanimated, Gesture Handler etc. to implement performant animations and gestures. Depending on the navigator, many UI components are written in JavaScript on top of React Native primitives. This has a lot of benefits:

    • 轻松进行 OTA 更新

      ¥Easy OTA updates

    • 可调试

      ¥Debuggable

    • 可定制

      ¥Customizable

  • 大多数应用都会大量自定义导航,要使用封装原生导航的 API 来实现此目的,你将需要编写大量原生代码。在 React Navigation 中,我们提供完全用 JavaScript 编写的导航器(例如 堆栈导航器)和在平台导航原语之上实现的导航器(例如 原生堆栈导航器)。这使你可以选择适合你的用例的导航器,具体取决于你是想要原生平台行为还是完全可定制性。

    ¥Most apps heavily customize navigation, to do this with an API that wraps native navigation you will need to write a lot of native code. In React Navigation, we provide navigators written fully with JavaScript (e.g. Stack Navigator) and navigators implemented on top of platform navigation primitives (e.g. Native Stack Navigator). This lets you pick the navigators suitable for your use case, depending on whether you want native platform behavior or full customizability.

  • 可以编写你自己的导航器,与标准导航器完全集成,或者分叉标准导航器并创建你自己的导航器版本,使其具有你在应用中想要的确切外观和感觉。

    ¥It's possible to write your own navigators that integrate cleanly with standard navigators, or to fork the standard navigators and create your own version of them with the exact look and feel you want in your app.

反俯仰

¥Anti-pitch

  • 改进可能需要重大改变。我们正在努力制作 "容易的事容易,困难的事可能",这可能需要我们有时更改 API。

    ¥Improvements may require breaking changes. We are working to make "easy things easy and hard things possible" and this may require us to change the API at times.

  • 有些导航器不直接使用 iOS 和 Android 上的原生导航 API;相反,他们使用最底层的部分,然后在顶部重新创建 API 的某些子集。这是一个有意识的选择,以便用户可以自定义导航体验的任何部分(因为它是用 JavaScript 实现的),并且能够调试他们遇到的问题,而无需学习 Objective C / Swift / Java / Kotlin 。

    ¥Some navigators don't directly use the native navigation APIs on iOS and Android; rather, they use the lowest level pieces and then re-creates some subset of the APIs on top. This is a conscious choice in order to make it possible for users to customize any part of the navigation experience (because it's implemented in JavaScript) and to be able to debug issues that they encounter without needing to learn Objective C / Swift / Java / Kotlin.

    • 如果你需要确切的平台行为,你可以选择使用使用原生平台原语的导航器(例如 原生堆栈导航器),或使用提供完全原生导航 API 的不同导航库(例如 React Native 导航)。

      ¥If you need the exact platform behavior, you can choose to use the navigators that use native platform primitives (e.g. Native Stack Navigator), or use a different navigation library which provides fully native navigation APIs (e.g. React Native Navigation).

  • 你可能还需要考虑其他限制,请参阅 局限性 了解更多详细信息。

    ¥There are other limitations which you may want to consider, see Limitations for more details.