Skip to main content

原生平台

你的应用可能需要访问 react-native 或社区维护的数百个 第三方库 之一无法直接提供的平台功能。也许你想重用 JavaScript 运行时中的一些现有 Objective-C、Swift、Java、Kotlin 或 C++ 代码。无论你出于何种原因,React Native 都会公开一组强大的 API 来将你的原生代码连接到你的 JavaScript 应用代码。

¥Your application may need access to platform features that aren’t directly available from react-native or one of the hundreds of third-party libraries maintained by the community. Maybe you want to reuse some existing Objective-C, Swift, Java, Kotlin or C++ code from the JavaScript runtime. Whatever your reason, React Native exposes a powerful set of API to connect your native code to your JavaScript application code.

本指南介绍:

¥This guide introduces:

  • 原生模块:没有用户界面 (UI) 的原生库。示例包括持久存储、通知、网络事件。这些可以作为 JavaScript 函数和对象供你的用户访问。

    ¥Native Modules: native libraries that have no User Interface (UI) for the user. Examples would be persistent storage, notifications, network events. These are accessible to your user as JavaScript functions and objects.

  • 原生组件:可通过 React 组件供应用的 JavaScript 代码使用的原生平台视图、小部件和控制器。

    ¥Native Component: native platform views, widgets and controllers that are available to your application's JavaScript code through React Components.

注意

你可能以前熟悉:

¥You might have previously been familiar with:

这些是我们已弃用的原生模块和组件 API。由于我们的互操作层,你仍然可以将许多这些旧版库与新架构一起使用。你应该考虑:

¥These are our deprecated native module and component API. You can still use many of these legacy libraries with the New Architecture thanks to our interop layers. You should consider:

  • 使用替代库,

    ¥using alternative libraries,

  • 升级到对新架构具有一流支持的较新库版本,或者

    ¥upgrading to newer library versions that have first-class support for the New Architecture, or

  • 自己将这些库移植到 Turbo Native 模块或 Fabric Native 组件。

    ¥port these libraries yourself to Turbo Native Modules or Fabric Native Components.

  1. 原生模块

    ¥Native Modules

  2. Fabric 原生组件

    ¥Fabric Native Components