Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Can you use libraries like https://github.com/tolu360/react-native-google-places in an Expo project? I assume any npm library is ok to add, but what about libraries like this google places picker that requires post install steps to link the native projects. Are they supported with Expo?

like image 942
MonkeyBonkey Avatar asked Jan 11 '17 17:01

MonkeyBonkey


People also ask

Can I use react native libraries with Expo?

Libraries built by Expo are all written in TypeScript and support iOS, Android, and react-native-web wherever possible.

Can I use native modules in Expo?

The tradeoff is that Expo Go does not allow you to add custom native code, you can only use native modules built into the Expo SDK. There are many great libraries available outside of the Expo SDK, and you may even want to build your own native library.

How do I add a native library to react native?

1) Add package name to new packages() 2) Add dependencies to settings. gradle file and main application's gradle i.e app/gradle file. 3) sync the projects gradle because you made changes in the gradle and it's done.


1 Answers

Regular Expo projects are written only in JavaScript and don't support npm packages that contain Objective-C or Java. However, Expo provides an advanced SDK called ExpoKit for when you absolutely need to use custom native code. From the Expo docs:

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.

You could "detach" your Expo project to create Xcode and Android Studio projects that contain ExpoKit. Then you would add custom Objective-C or Java the same way as with any other Xcode or Android Studio project.

However, the Expo docs also warn about some of the downsides of writing custom native code; many features often can be implemented well in JS, allowing you to retain all of the benefits of a standard Expo project.

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.

like image 101
ide Avatar answered Sep 30 '22 18:09

ide