-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Comments
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 Definitely a lot of scope for to build on the work of Phonegap/Cordova. |
It'd be really interesting to build a phonegap (and maybe an ionic) bridge to React-Native |
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 ::
|
@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? |
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 ::
|
@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. |
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. |
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 ::
|
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? |
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. |
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? |
@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. |
@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: Does anyone know of patterns documented for sharing modules? |
Most likely they can be made available as NPM packages following the pattern of everything currently in You could imagine the same setup, but with a I have some ideas for generating a 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. |
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 :( |
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.
|
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. |
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 !! |
@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. |
Here is a demo of how it works today - https://www.youtube.com/watch?v=h_fKByit6IY |
@axemclion Nice work! Hope it will support iOS soon |
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.
The text was updated successfully, but these errors were encountered: