- Please install react-native-create-library library for creating a base structure of your Native Module
npm install -g react-native-create-library
- Navigate into an empty directory to execute the command:
$ react-native-create-library MyNativeModule
This will generate native Android, iOS & Windows library projects, based on your need to can remove other platform generated libraries.
- Automatic
$ npm install react-native-my-native-module --save
$ react-native link react-native-my-native-module
- Manually
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-my-native-module
and addRNMyNativeModule.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNMyNativeModule.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNMyNativeModulePackage;
to the imports at the top of the file - Add
new RNMyNativeModulePackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-my-native-module' project(':react-native-my-native-module').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-my-native-module/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-my-native-module')
- In Visual Studio add the
RNMyNativeModule.sln
innode_modules/react-native-my-native-module/windows/RNMyNativeModule.sln
folder to their solution, reference from their app. - Open up your
MainPage.cs
app
- Add
using My.Native.Module.RNMyNativeModule;
to the usings at the top of the file - Add
new RNMyNativeModulePackage()
to theList<IReactPackage>
returned by thePackages
method