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

[Bridge] Native module inside framework #579

Closed
voximplant opened this issue Apr 1, 2015 · 18 comments
Closed

[Bridge] Native module inside framework #579

voximplant opened this issue Apr 1, 2015 · 18 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@voximplant
Copy link

Is there a way to implement native module inside framework instead of static library?

@a2
Copy link
Contributor

a2 commented Apr 1, 2015

As of now, this is not possible because React Native looks for all RCT_EXPORT entries in its binary.

@voximplant
Copy link
Author

Sometimes developer needs to use native modules inside frameworks. For example, it's required to avoid build problems because of the conflicts between 3rd party libs code and React Native libs.
Can we propose to extend React Native functionality to let Objective-C class that implements RCTBridgeModule has an option to return list of methods for export to JS?

@drkibitz
Copy link
Contributor

drkibitz commented Apr 1, 2015

Not exactly sure I am following this issue, but I'm interested. Is the question if you can add a new Framework that utilizes react native and exposes functionality?

@ide
Copy link
Contributor

ide commented Apr 1, 2015

@drkibitz yes, if you publish e.g. a keyboard component that has some native code, it currently has to be distributed as a static library. This means you can't write helper code in Swift without splitting it out into a separate framework.

So far I've found RCT_EXPORT easy to type and maintain so it would be nice to keep it or something very similar. Maybe it (or a new macro) could generate dummy methods that RCTBridge knows to scan for?

@a2
Copy link
Contributor

a2 commented Apr 1, 2015

Alright, I'm currently working on an updated version of RCT_EXPORT and I will look into making this possible.

@a2 a2 self-assigned this Apr 1, 2015
@ide
Copy link
Contributor

ide commented Apr 1, 2015

@a2 That sounds really great. One of the practical benefits of framework support is that you can use CocoaPods containing Swift -- if a pure-ObjC pod (e.g. a React module) depends on a pod with Swift code (e.g. Alamofire, whatever) then CocoaPods builds both as frameworks.

@voximplant
Copy link
Author

@a2 sounds good, will be waiting eagerly!

@tptee
Copy link

tptee commented Apr 3, 2015

👍 this is the last thing blocking my WebSockets native extension: https://github.com/tptee/RCTWebSocket

This'll help distribution/CocoaPods interop immensely.

@voximplant
Copy link
Author

Any news?

@tptee
Copy link

tptee commented Apr 25, 2015

#982 is done, which is awesome, but I'm not sure frameworks work yet. When CocoaPods builds a framework, it spits all of the project's headers into one folder, and a few headers in React Native reference relative paths. This breaks clang modules, which CocoaPods framework support depends on. So while we can write extensions in Swift, we can't deliver them in a clean way yet :/

@nicklockwood
Copy link
Contributor

That's true. I'm working on it :-)

@tptee
Copy link

tptee commented Apr 25, 2015

👍

@tptee
Copy link

tptee commented Apr 29, 2015

As of 0.4.1 I can successfully build a framework linked to React with the new Swift export macros. However, when I import the framework module into a React Native app target, I get the following:

Class WebSocketManager was not exported. Did you forget to use RCT_EXPORT_MODULE()?

Any ideas? Looks like RCT_EXTERN_MODULE didn't export the class from the framework correctly.

@nicklockwood
Copy link
Contributor

That's correct, we still don't support modules linked from dynamic libraries yet. That's coming soon.

@tptee
Copy link

tptee commented Apr 29, 2015

Cool, thanks for the update!

On Apr 29, 2015, at 7:47 PM, Nick Lockwood notifications@github.com wrote:

That's correct, we still don't support modules linked from dynamic libraries yet. That's coming soon.


Reply to this email directly or view it on GitHub #579 (comment).

@a2 a2 assigned nicklockwood and unassigned a2 Apr 30, 2015
@brentvatne brentvatne changed the title Native module inside framework [Bridge] Native module inside framework May 31, 2015
@yusefnapora
Copy link
Contributor

To update this, as of 0.7.0-rc.2, I was able to define a module in a shared framework and use it from an iOS app target. The new module loading system seems to have done away with embedding strings into the binaries in favor of a registration system based on defining + (void) load on native module classes.

As far as I can tell, things work perfectly. Adding React to an existing project using CocoaPods with use_frameworks! runs without issue, and you can define native modules in frameworks.

@ide
Copy link
Contributor

ide commented Jul 6, 2015

@yusefnapora thanks for the update!

@ide ide closed this as completed Jul 6, 2015
@colinhang
Copy link

@yusefnapora @nicklockwood Has this issue been fixed? Could you please show me the commit? I a m still not able to link dynamic library (.framework) into my RN project. There are many 3rd party solutions to create native UI components using objective-c and we can easily integrate them into a RN project as they target static library.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 6, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
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

Successfully merging a pull request may close this issue.

8 participants