nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
22.99k stars 2.3k forks source link

Generate react-native library with native code: Kotlin, Swift #11181

Open whalemare opened 2 years ago

whalemare commented 2 years ago

Description

I want to generate react-native library that includes not only js code, but also native part with Kotlin, Swift https://nx.dev/packages/react-native/generators/library

Motivation

Native dependencies it's important part of any react-native project. NX already supported react-native libraries with native code, but can't generate it yet

Suggested Implementation

Usage: something like that yarn nx g @nrwl/react-native:library --withNativePart

Alternate Implementations

-

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

whalemare commented 1 year ago

Not stale

lego-sharat commented 1 year ago

in nx react native app, how can i use a library with react native code? Thanks in advance. @whalemare

gokulkulkarni1987 commented 11 months ago

This is very much required feature, especially for react-native @whalemare thanks for filing this.

Tom-Bury commented 7 months ago

You can do it by generating a local RN library using create-react-native-library.

Afterwards you can manually link this library in your NX workspace by adjusting the workspace.json and copying over any other config files in the library. Create a plain TS RN library using NX as example and copy over the files for linting, TS, ...

Note that in order for RN autolinking to work properly, you will need to add this local package as a dependency in each app that needs to use it. So you will have:

// In the root package.json the following is added by create-react-native-library:
"dependencies": {
  "local-rn-library": "link:./modules/awesome-library"
}

// In the package.json of any apps that need the library you need to add:
"dependencies": {
  "local-rn-library": "*"
}