This project serves as a PlayFrequency to create custom React Native native modules that can later be installed through NPM and easily be used in production.
- Clone the project
- Customize the project name by doing the following:
-
Edit
authorandnameinpackage.json -
Customize the Java package name (
com.domain.package) as follows:- Modify it in
android/src/main/AndroidManifest.xml. - Rename the folders starting from
android/src/main/javato match your package name. - Adjust
package com.play.frequency;in the top of theModule.javaandPackage.javafiles inandroid/src/main//java/package/pathto match it.
- Modify it in
-
Edit the name of your module in
@Override public String getName() { return "PlayFrequency"; }
and adjust it in
index.android.js
-
- Modify/Build the Project in Android Studio
- Start
Android Studioand selectFile -> New -> Import Projectand select the android folder of this package. - If you get a
Plugin with id 'android-library' not foundError, installandroid support repository. - If you get asked to upgrade gradle to a new version, you can skip it.
- Start
There are many ways to do this, here's the way I do it:
-
Push it to GitHub.
-
Do
npm install --save git+https://github.com/shivali123/react-native-play-frequency.gitin your main project. -
Link the library:
-
Add the following to
android/settings.gradle:include ':react-native-play-frequency' project(':react-native-play-frequency').projectDir = new File(settingsDir, '../node_modules/react-native-play-frequency/android') -
Add the following to
android/app/build.gradle:... dependencies { ... compile project(':react-native-play-frequency') } -
Add the following to
android/app/src/main/java/**/MainApplication.java:package com.motivation; import com.play.frequency.Package; // add this for react-native-play-frequency public class MainApplication extends Application implements ReactApplication { @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new Package() // add this for react-native-play-frequency ); } }
-
-
Simply
import/requireit by the name defined in your library'spackage.json:import PlayFrequency from 'react-native-play-frequency' PlayFrequency.play(300)
-
You can test and develop your library by importing the
node_moduleslibrary into Android Studio if you don't want to install it from git all the time.