Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native using Cocoapods

Is it possible to use cocoapods when using React Native?

If so, How can I require in JavaScript the pods projects?

Thanks in advance!

like image 612
gran33 Avatar asked Aug 09 '15 06:08

gran33


People also ask

Does React Native use CocoaPods?

React Native uses Cocoapods to add iOS dependencies when you add new modules to your application. Cocoapods is a dependency manager for the Apple development ecosystem.

Why do I need CocoaPods for React Native?

CocoaPods allows you to add code to run before and at the end of the Podfile via installation hooks. You probably already have some custom code in there. This plugin allows all that code to be centralized and reasoned about in a single place per React Native version.

Should I install CocoaPods with GEM or homebrew?

I would suggest you install CocoaPods using brew . It's a little cleaner option and you can update it easier. The cocoapods cask is for CocoaPads App and the formula is for the CLI only version.


1 Answers

Yes. It's possible. React Native project is pretty much normal iOS application (In terms of XCode required to build it and quite a lot of React Native internal code is well... Native Obj-C). Since React Native project is already run via xcworkspace, so it's perfectly possible to add Obj-C pods to the ReactNative project.

Since a lot of dependencies used by RN apps are pure javascript rather than Obj-C code, it's more than convenient to keep both dependency systems - Cocoapods (for Obj-C dependencies) and npm (for javascript). Pods are kept in "Pods" directory and npm under "node-modules" and they are not clashing with each other. And it's pretty convenient actually to have different types of dependencies run by different dependency management systems.

UPDATE: by default ReactNative project is .xcodeproj based, but it's easy to convert it to .xcodeworkspace.

I even tried to add React Native itself as Cocoapods dependency and it was sort of working (but some dependencies expected React in the "node-modules" dir so I abandoned it).

like image 76
Jarek Potiuk Avatar answered Oct 08 '22 13:10

Jarek Potiuk