您可以将具有本机依赖项的库添加到 Expo React 本机项目中吗?

Can you add libraries with native dependencies to an Expo react native project?

您可以在 Expo 项目中使用像 https://github.com/tolu360/react-native-google-places 这样的库吗?我假设任何 npm 库都可以添加,但是像这样的库如何 google 放置需要 post 安装步骤到 link 本机项目的选择器。他们支持 Expo 吗?

常规 Expo 项目仅使用 JavaScript 编写,不支持包含 Objective-C 或 Java 的 npm 包。但是,当您绝对需要使用自定义本机代码时,Expo 提供了一个名为 ExpoKit 的高级 SDK。来自 Expo 文档:

Normally, Expo apps are written in pure JS and never “drop down” to the native iOS or Android layer. This is core to the Expo philosophy and it’s part of what makes Expo fast and powerful to use.

However, there are some cases where advanced developers need native capabilities outside of what Expo offers out-of-the-box. The most common situation is when a project requires a specific Native Module which is not supported by React Native Core or the Expo SDK.

您可以 "detach" 您的 Expo 项目来创建包含 ExpoKit 的 Xcode 和 Android Studio 项目。然后您将添加自定义 Objective-C 或 Java,就像添加任何其他 Xcode 或 Android Studio 项目一样。

但是,Expo 文档也警告了编写自定义本机代码的一些缺点;许多功能通常可以在 JS 中很好地实现,让您保留标准 Expo 项目的所有好处。

Warning: We discourage most of our developers from taking this route, as we believe almost everything you need to do is better accomplished in a cross-platform way with JS.

Writing in JS enables you to best take advantage of over-the-air code deployment and benefit from ongoing updates and support from Expo. You should only do this if you have a particular demand from native code which Expo won’t do a good job supporting, such as (for example) specialized CPU-intensive video processing that must happen locally on the device.