gkeenley
gkeenley

Reputation: 7378

How to add native modules in React Native 0.60+?

I'm trying to understand the difference between the autolinking that exists in React Native 0.60+ and the automatic / manual linking we have in previous React Native versions. When I add react-native-gesture-handler with npm i react-native-gesture-handler, no lines are added to my Podfile. So when I do pod install, I assume the Gesture Handler module isn't linked. However, if I link it manually as I did with previous React Native versions, by dragging the .xcodeproj files into Libraries etc, it throws an error and tells me to unlink it.

What I Want To Know:

Am I right that what autolinking does is adds a line for the given module to your Podfile, which then gets linked when you pod install? If so, why might it be that when I did npm i react-native-gesture-handler nothing was added to my Podfile? And given that nothing was added and linking the module manually throws an error, how should I link the module?

Upvotes: 1

Views: 1913

Answers (1)

Mehran Khan
Mehran Khan

Reputation: 3636

When you create a new project and react-native version >=60 , this line is automatically added in pod file (official site)

# example/ios/Podfile
require_relative '../../node_modules/@react-native-community/cli-platform-ios/native_modules'

This is path of script , so when you run "pod install" , it will check all libraries and install all pods files required

So when you add new library , no lines are added to my Podfile but you have to run "pod install" so that script file can run and install new pod files .

Please do not use manual linking as described in official site

This means that all libraries need to ship a Podspec either in the root of their folder or where the Xcode project is. Podspec references the native code that your library depends on.

The implementation ensures that a library is imported only once. If you need to have a custom pod directive then include it above the use_native_modules! function.

You have to do 2 steps

1 : Add library "yarn add react-native-gesture-handler"

2 : cd ios && pod install

Upvotes: 2

Related Questions