Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you use phonegap/cordova plugins with react native? #230

Closed
wootwoot1234 opened this issue Mar 26, 2015 · 22 comments
Closed

Can you use phonegap/cordova plugins with react native? #230

wootwoot1234 opened this issue Mar 26, 2015 · 22 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@wootwoot1234
Copy link

Does react native support using phonegap/cordova plugins? Or would it be easy to port them over? Seems like there is a lot of work there that could be borrowed from.

@JoeStanton
Copy link
Contributor

You can't just plug them in, but it's trivial to expose very similar Objective-C classes to the JS bridge (effectively you'd just need to implement the RCTBridgeModule protocol instead).

Definitely a lot of scope for to build on the work of Phonegap/Cordova.

@benjamingr
Copy link

It'd be really interesting to build a phonegap (and maybe an ionic) bridge to React-Native

@jaygarcia
Copy link
Contributor

What would be the advantage to doing this? I imagine it's possible to wrap the PhoneGap view, but I don't see why.

JG

:: sent from my mobile device ::

On Mar 26, 2015, at 15:09, Benjamin Gruenbaum [email protected] wrote:

It'd be really interesting to build a phonegap (and maybe an ionic) bridge to React-Native


Reply to this email directly or view it on GitHub.

@wootwoot1234
Copy link
Author

@jaygarcia plugins or ionic? I think plugins could be really useful since currently react native is limited in how it can interact with the hardware. Ionic by itself is a very nice mobile html5 framework but I'm not sure how it would fit in with react native. They have have done a great job with ngCordova and it might be a good starting point for which plugins to port to react native.

React native could use some plugins, right? I'm not missing something am I?

@jaygarcia
Copy link
Contributor

I agree that react could use plugins. I am speaking to why you would want to migrate or bridge cordova with react native.

The whole purpose of using this framework is so that you can get away from the limitations of HTML5.

Like I said, wrapping cordova might actually be trivial to do. I just can't see the "why" :)

JG

:: sent from my mobile device ::

On Mar 26, 2015, at 20:22, wootwoot1234 [email protected] wrote:

@jaygarcia plugins or ionic? I think plugins could be really useful since currently react native is limited in how it can interact with the hardware. Ionic by itself is a very nice mobile html5 framework but I'm not sure how it would fit in with react native. They have have done a great job with ngCordova and it might be a good starting point for which plugins to port to react native.

React native could use some plugins, right? I'm not missing something am I?


Reply to this email directly or view it on GitHub.

@wootwoot1234
Copy link
Author

@jaygarcia Cordova plugin don't use html, at least none that I can think of. They are purely javascript to native which is what react native plugins would be. I'm all about react native and not using a webviews but cordova plugins don't have anything to do with the webview. So to answer "why", because cordova has done 90% of the ground work, just need to change the bridge from cordova to react native. Maybe I don't understand what you mean or maybe you don't know what a cordova plugin is but I can't think of why not.

@joewood
Copy link

joewood commented Mar 27, 2015

It would be great to see the react-native Bridge protocol documented so the community could take on the job of converting Cordova plugins to RN generically. Especially now both will be using npm.

@jaygarcia
Copy link
Contributor

I am very well versed in the cordova universe and how plugins are made. I wrote a mod player app using cordova and Sencha touch in 2013 :).

I can see porting of plugins. Just not bridging cordova as a library and react native. That's what I am getting at.

JG

301.785.6030 :: @moduscreate

:: sent from my mobile device ::

On Mar 27, 2015, at 00:09, wootwoot1234 [email protected] wrote:

@jaygarcia Cordova plugin don't use html, at least none that I can think of. They are purely javascript to native which is what react native plugins would be. I'm all about react native and not using a webviews but cordova plugins don't have anything to do with the webview. So to answer "why", because cordova has done 90% of the ground work, just need to change the bridge from cordova to react native. Maybe I don't understand what you mean or maybe you don't know what a cordova plugin is but, I can't think of why not.


Reply to this email directly or view it on GitHub.

@joewood
Copy link

joewood commented Mar 27, 2015

I think porting should be fairly easy already, as extensibility is well documented. The main difference would be that Cordova's native modules are running in a worker, where react-native is bridging to the UI thread. Right?

@jaygarcia
Copy link
Contributor

I believe so. The one thing to think about is that with React Native, plugins / extensions are bound the React Native runloop. I was bit by this when writing a custom audio player.

@joewood
Copy link

joewood commented Mar 27, 2015

Just to understand what you mean, the native extensions are on the UI thread, so therefore should not be blocking? Is the port of your phonegap mod player plugin to an RN extension open-source?

@frantic
Copy link
Contributor

frantic commented Mar 27, 2015

@jordwalke had the same idea but we didn't have time to look closely at it. I think it is possible to build an adapter that takes cordova plugin and exposes it as RN module in JS.

@jaygarcia
Copy link
Contributor

@joewood, yes, that's what i'm saying.

The code is not yet open sourced. I have yet to fully understand how the Facebook team wants open-source modules to be released - that is the pattern to do this. There is the ObjC code, and related JavaScript that needs to somehow be bundled.

For a preview of some code:
#114 (comment)

Does anyone know of patterns documented for sharing modules?

@JoeStanton
Copy link
Contributor

Most likely they can be made available as NPM packages following the pattern of everything currently in /Libraries/. See my Vibration API example that was included in core: #154

You could imagine the same setup, but with a package.json in the library folder, of which it's contents could be published to NPM. These libraries can then be statically linked into your Xcode Project via the node_modules dir (which would be a manual step for now).

I have some ideas for generating a react-native new-library command that would remove the need for some of this boilerplate and ease the creation of these libraries.

And yes - We were referring to @frantic / @jordwalke's idea of adapting Cordova modules to something the bridge could consume. Thinking about it more I think it might not be worth the effort, but there is definitely some stuff we could learn/benefit from in Cordova plugins.

@joewood
Copy link

joewood commented Mar 27, 2015

I notice that @ide posted this #235 and there was this discussion we had when it was in private beta #60. npm being the master and seeding the xcode build through pod files. Not sure if that was the final agreement though.

@jaygarcia
Copy link
Contributor

I'd like to add a note that the API for exposing ObjC to JS is volatile.

I just got bit by a change to the RCT_CUSTOM_VIEW_PROPERTY macro :(

@sahrens
Copy link
Contributor

sahrens commented Mar 27, 2015

The native calls are not made on the main thread so as not to hurt scrolling or other interactions, but you can jump onto whatever other thread you want in the native code. For example, parts of GeoLocation must run on the main thread, and AsyncStorage has its own queue for file operations.

Following Joe Stantons model for vibration would be perfect for other extensions. A folder with an xcodeproj, native files, JS files, and a package.json. Then a user of it would pull it into node_modules, drag the xcodeproj into Xcode, and link the lib.

On Mar 27, 2015, at 7:48 AM, Jay Garcia [email protected] wrote:

I'd like to add a note that the API for exposing ObjC to JS is volatile.

I just got bit by a change to the RCT_CUSTOM_VIEW_PROPERTY macro :(


Reply to this email directly or view it on GitHub.

@brentvatne
Copy link
Collaborator

Discussion went a bit off track here, I believe the original question has been answered. Closing, feel free to ping me if I'm off base here and I'll re-open.

@axemclion
Copy link
Contributor

Here is something I am attempting. I got a basic plugin working - http://github.com/axemclion/react-native-cordova-plugin for Cordova. I am able to call a simple Cordova plugin from reactNative. Still need to wire in the javascript, and add more capabilities - working on those soon !!

@bendikl
Copy link

bendikl commented Oct 12, 2015

@axemclion Sweet! Looking forward to hearing the progress on iOS with this one. Also hoping that @JoeStanton and @jaygarcia are able to contribute on the new Plugin Adapter.

@axemclion
Copy link
Contributor

Here is a demo of how it works today - https://www.youtube.com/watch?v=h_fKByit6IY
Explanation of how it works - http://blog.nparashuram.com/2015/10/using-cordova-plugins-in-react-native.html
One thing I did realize is that we do need a good plugin manager for ReactNative. We could learn from Cordova and NativeScript's plugin managers !!

@dzcpy
Copy link

dzcpy commented May 1, 2016

@axemclion Nice work! Hope it will support iOS soon

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
react-one pushed a commit to react-one/react-native that referenced this issue Sep 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests