Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native link only for one project (Android or iOS)

I want to link only one of my project (Android or iOS) with the npm package. Is there any way to do it?

like image 330
Aaditya Paliwal Avatar asked Aug 02 '18 05:08

Aaditya Paliwal


People also ask

Can we combine native iOS or Android code in react-native?

Yes, we can. React Native smoothly combines the components written in Objective-C, Java, or Swift.

What is deep linking in react-native?

Deep Linking is a technique in which a given URL or resource is used to open a specific page or screen on mobile. So, instead of just launching the app on mobile, a deep link can lead a user to a specific screen within the app, providing a better user experience.


2 Answers

You can choose to link libraries for only a certain platform by doing:

For Android: react-native link (your_library_name_here) --platforms android

For iOS: react-native link (your_library_name_here) --platforms ios

like image 53
Ennis Machta Avatar answered Sep 19 '22 18:09

Ennis Machta


if react-native < 60

  1. rename platforms ( iOS or Android) that you don't want to link.
  2. run react-native link your-library-js-package-name.
  3. rename platforms to the original name.

.

react-native >= 60

because the new react-native versions have some auto-linking feature you should tell the react-native CLI to do not link your library:

  1. create a react-native.config.js file in the root of your project.
  2. add some config like this

    module.exports = {
      dependencies: {
        'your-library-js-package-name': {
             platforms: {
               android: null, // assign null to disable autolinking
               ios: // assign null to disable autolinking or remove the 
                    ios key to let do the default linking
            },
        },
    
      },
    };
    

check this for more info docs

like image 22
Ahmad Dehnavi Avatar answered Sep 20 '22 18:09

Ahmad Dehnavi