All Projects → axemclion → React Native Cordova Plugin

axemclion / React Native Cordova Plugin

Licence: isc
Cordova Plugin Adapter for React Native

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Cordova Plugin

cordova-plugin-flurryanalytics
Adds support for all that Flurry Analytics flavored goodness to your Cordova based apps
Stars: ✭ 23 (-94.74%)
Mutual labels:  cordova-plugin
scanbot-sdk-example-ionic
Scanbot scanner SDK example app for Ionic with Cordova.
Stars: ✭ 24 (-94.51%)
Mutual labels:  cordova-plugin
Cordova qq
A Cordova wrapper around the Tencent QQ SDK for Android and iOS. Provides access to QQ ssoLogin, QQ Sharing, QQZone Sharing etc.
Stars: ✭ 294 (-32.72%)
Mutual labels:  cordova-plugin
cordova-plugin-foxitpdf
Cordova plugin for Foxit PDF SDK to View PDF Files
Stars: ✭ 19 (-95.65%)
Mutual labels:  cordova-plugin
ionic-native-sms-retriever-plugin-master
Cross-platform plugin for Cordova / PhoneGap to Retrieve SMS. Available for Android.
Stars: ✭ 16 (-96.34%)
Mutual labels:  cordova-plugin
Cordova Plugin Geofence
Geofencing plugin for cordova
Stars: ✭ 261 (-40.27%)
Mutual labels:  cordova-plugin
example-cordova-code-push-plugin
Ionic + Cordova Code Push Plugin Example
Stars: ✭ 45 (-89.7%)
Mutual labels:  cordova-plugin
Cordova Plugin App Version
Cordova plugin to return the version number of the current app
Stars: ✭ 374 (-14.42%)
Mutual labels:  cordova-plugin
cordova-plugin-smartconfig
A cordova plugin for Smart Configure ESP8266 & ESP32 with Espressif Esptouch protocol.
Stars: ✭ 17 (-96.11%)
Mutual labels:  cordova-plugin
Cordova Plugin App Update
App updater for Cordova/PhoneGap
Stars: ✭ 290 (-33.64%)
Mutual labels:  cordova-plugin
cordova-plugin-tesseract
Cordova Plugin for OCR process using Tesseract
Stars: ✭ 70 (-83.98%)
Mutual labels:  cordova-plugin
cordova-plugin-today-widget
Add a today widget app extension target to your cordova project.
Stars: ✭ 51 (-88.33%)
Mutual labels:  cordova-plugin
Cordova Plugin Printer
Print HTML documents
Stars: ✭ 265 (-39.36%)
Mutual labels:  cordova-plugin
cordova-plugin-apkupdater
This plugin allows your Android app to download and install compressed updates without the Google Play Store.
Stars: ✭ 46 (-89.47%)
Mutual labels:  cordova-plugin
Vue Cordova
Vue.js plugin for Cordova
Stars: ✭ 328 (-24.94%)
Mutual labels:  cordova-plugin
cordova-plugin-dbcopy
Copy SQLite Database from www folder to default app database location
Stars: ✭ 90 (-79.41%)
Mutual labels:  cordova-plugin
ionic-signature-pad
Ionic plugin to input singnature pad
Stars: ✭ 15 (-96.57%)
Mutual labels:  cordova-plugin
Cordova Plugin Badge
Access and modify badge numbers
Stars: ✭ 386 (-11.67%)
Mutual labels:  cordova-plugin
Cordova Plugin Email Composer
Edit and send email messages
Stars: ✭ 333 (-23.8%)
Mutual labels:  cordova-plugin
Cordova Plugin Nativestorage
Cordova plugin: Native storage of variables in Android, iOS and Windows
Stars: ✭ 285 (-34.78%)
Mutual labels:  cordova-plugin

React-Native Cordova Plugin Adapter

A way to use Cordova plugins in React-Native Applications

Why?

The Cordova plugin ecosystem is diverse and rich. Many native device capabilities are already available as a plugin with a W3C like Javascript API in most cases. Using them to access native capabilities from React Native can be done using Cordova plugins without having to rewrite all those plugins.

How?

To start using Cordova Plugins in your ReactNative project, follow these steps

  1. Getting Started
  2. Setup your ReactNative project with this react-native-cordova-plugin module.
  3. Add/Removing the required Cordova Plugin to the ReactNative project. (link)
  4. Use the required Cordova Plugin in your ReactNative Javascript code. (link)

You can also check out the example project in the example branch of this repository.

Step 0 - Getting Started

First, Install this native module in your ReactNative project by running the following at the root of your ReactNative Project.

npm install react-native-cordova-plugin --save

Step 1 - Setup the ReactNative project

As with all other React Native plugins, the integration experience is different for iOS and Android, so perform the next set of setup steps depending on which platform(s) you are targetting.

Step 1.1 For Anrdoid

  1. In android/settings.gradle file, make the following changes
  include ':app'
+ include ':cordovaplugin'
+ project(':cordovaplugin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cordova-plugin/framework/android')
  1. In android/app/build.gradle, look for dependencies section and add the following line
...
android {
  ...
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules    ...
+   compile project(':cordovaplugin')
}

  1. In android/app/src/main/java/com/appname/MainActivity.java (your main Android activity file), add a reference to react-native-cordova-plugin.
...
+  import io.cordova.reactnative.CordovaPluginPackage;
...
public class MainActivity extends ReactActivity {
     ...
     @Override
     protected List<ReactPackage> getPackages() {
         return Arrays.<ReactPackage>asList(
                 new MainReactPackage(),
+                cordovaPluginPackage = new CordovaPluginPackage(this)
         );
     }
+    private CordovaPluginPackage cordovaPluginPackage;
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        cordovaPluginPackage.setSavedInstanceState(savedInstanceState);
+    }
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+        super.onActivityResult(requestCode, resultCode, intent);
+        cordovaPluginPackage.onActivityResult(requestCode, resultCode, intent);
+    }
}

Step 3 - Adding Cordova Plugin to ReactNative project

To install a plugin, say the cordova-plugin-camera and cordova-plugin-contacts, run the following command from the root of your ReactNative project

$ node_modules/.bin/cordova-plugin add cordova-plugin-camera cordova-plugin-contacts

You can install plugins that require variables as well. Here we add the Cordova purchase plugin that handles In App Purchasing, supplying it the Billing Key of our Android application. You would replace the fake billing key (MIIBFJIEOF....) with your billing key (a very long string).

$ node_modules/.bin/cordova-plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="MIIBFJIEOF...."

The add command takes one of more Cordova plugins that can be added to the project. To remove a plugin, use

$ node_modules/.bin/cordova-plugin rm cordova-plugin-contacts

Step 4 - Using the Plugins

In either index.android.js or any other component, simply require this module using

var Cordova = require('react-native-cordova-plugin');

In Cordova, all plugin methods are available on the window object. ReactNative does not run in a WebView and does not have a window object. Thus, all the methods and constants that a Cordova plugin defines are available in the Cordova object that was just required using the statement above.

Cordova.navigator.camera.getPicture(onSuccess, onFail, {sourceType: Cordova.Camera.PictureSourceType.SAVEDPHOTOALBUM)});

// Listen to cordova-plugin-network-information plugin's events
Cordova.addEventListener('offline', onEvent);

There are more examples of using the plugins in the examples branch - look for files with plugin names.

Older Versions

To run this plugin for older versions of ReactNative, use older versions published on npm

To use CLI commands with react-native-cordova-plugin versions less than 1.0.0, replace $ node_modules/.bin/cordova-plugin with $ node_modules/.bin/react-native-cordova-plugin.

Troubleshooting

Some JavaScript errors may be caused due to the way cordova.js is generated. You can try tto re-generate cordova.js using

$ node_modules/.bin/cordova-plugin repair

If that does not work, try cleaning all the cordova plugins using the following, and then add the plugins again

$ node_modules/.bin/cordova-plugin clean

If none of these work, please open an issue with a prefix [QUESTION] in the title, and I could try helping you. It would help to open the issue with a reduced way to reproduce the error.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].