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

Support use without react-native link; add .podspec for libraries #94

Closed
koenpunt opened this issue Aug 22, 2017 · 5 comments · Fixed by #177
Closed

Support use without react-native link; add .podspec for libraries #94

koenpunt opened this issue Aug 22, 2017 · 5 comments · Fixed by #177

Comments

@koenpunt
Copy link

I have a so-called "brownfield" app; a native iOS Swift app with integrated React Native views.

To do this I had to add all React libraries as CocoaPods dependencies. But now when I add mobile-center as npm dependency and run react-native link, it's added correctly, but the project doesn't build because the linked project can't find the React library files.

Up until now for all other libraries installed through npm, there was always a podspec file for the React Library too. So I just referred to the local podspec file in the node_modules directory, and didn't have to use react-native link.

So my question is; can there be podspecs added to the different libraries? Or would you accept a PR that does so?

@dhei
Copy link
Member

dhei commented Aug 23, 2017

Hi @koenpunt,

Thanks for reaching out.

Can you explain a little bit what do you mean by this of linking your app? What react library files?

it's added correctly, but the project doesn't build because the linked project can't find the React library files.

We'd also like to you learn more about your scenario of "brownfield" app. Just out of curiosity, have you considered using our iOS SDK, is there anything that you specifically need from the React-Native SDK?

Thanks.

@koenpunt
Copy link
Author

Hi @dhei,

The bridge classes (e.g. RNMobileCenter) import headers from react (e.g. React/RCTBridgeModule.h), and in a react-native init'ed app this would work because the react headers are added as a subproject.
But since my react classes are linked to the project as a dynamic framework using CocoaPods, the linked xcode project (RNMobileCenter.xcodeproj) can't find the react headers.

To support both ways most libraries include podspec's to be able to include the classes using cocoapods too.

So to give an example, part of my Podfile currently looks like this:

  pod 'React', path: '../node_modules/react-native', subspecs: [
    'Core',
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # needed for debugging
    'BatchedBridge',
    'RCTImage',
    'DevSupport',
    'RCTAnimation',
    'RCTActionSheet',
    'RCTLinkingIOS',
  ]
  pod 'Yoga', path: '../node_modules/react-native/ReactCommon/yoga'

  pod 'react-native-safari-view', path: '../node_modules/react-native-safari-view'
  pod 'react-native-fbsdk', path: '../node_modules/react-native-fbsdk/ios'
  pod 'react-native-google-analytics-bridge', path: '../node_modules/react-native-google-analytics-bridge'
  pod 'RNStoreReview', path: '../node_modules/react-native-store-review/ios'

As you can see I installed all these libraries using NPM, but installed them using CocoaPods.

I think the react-native-fbsdk is a good demonstration on how to set this up: https://github.com/facebook/react-native-fbsdk/tree/master/ios

Just out of curiosity, have you considered using our iOS SDK, is there anything that you specifically need from the React-Native SDK?

Yes, and I can of course initialize the SDK, but there's no way to interact with the native SDK from react native without the bridge classes.

@dhei
Copy link
Member

dhei commented Sep 12, 2017

@koenpunt, my apologies for long delay in responding here. Thanks for providing the detailed information of your scenario. This is a very common scenario and we plan to support it after React Native merging this PR (facebook/react-native#15460). Based on this PR, react-native link will support the following scenario out-of-box:

This change will allow to link projects that contains its own .podspec file to CocoaPods-based projects. In case link detect Podfile in iOS directory, it will look for related .podspec file in linked project directory, and add it to Podfile. If Podfile and .podspec files are not present, it will fall back to previous implementation.

Thanks for the patience. We will update this thread once we support this scenario.

@koenpunt
Copy link
Author

This is a very common scenario and we plan to support it

Good!

and we plan to support it after React Native merging this PR

Why wait for that? Because what I understand from the discussion there, is that they haven’t decided what the right approach would be, which means that it could still take months to land. Where if the podspecs are available earlier it can be used manually like is the case for every other library with a podspec

@johannth
Copy link

johannth commented Nov 3, 2017

It seems that facebook/react-native#15460 has been merged and will probably be included in 0.50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants