iOS Development

Distributing React Native as a part of an iOS Framework: How?

Spread the love

I am taking part in round with some potential mechanisms to ship a React-Native app as a framework. Particularly, it will have three elements:

  1. RN App – this has a module that I need to expose by way of a helper within the framework to be used within the consumer app.
  2. Framework (iOS Native Swift) – this wraps the bundle.js from the RN app within a Framework.
  3. Shopper App (iOS Native Swift) – Provides the Framework and makes use of the helper within the Framework to get the React Native module (on this case, a View) for use within the Shopper App UI.

So, which means that the framework pulls in React Native by way of Cocoapods as a result of it’s straight interfacing with the React Native parts. That is at present accomplished like this:

goal 'TestAppFramework' do
  config = use_native_modules!
    :path => config[:reactNativePath],
    :fabric_enabled => true,  
    :ios_folder => 'TestAppFramework'

The use_react_native methodology maps again to react_native_pods.rb within the react challenge. That is the place the pods really get pulled in. There are roughly 50 of them.

Potential static resolution

By default, RN pulls stuff in statically. I am not utilizing use_frameworks! contained in the Podfile. My expectation primarily based off of this may be that pod dependencies can be constructed into the framework. After I drop this framework into my consumer challenge, it fails to compile as a result of a generated -Swift.h header can’t discover react in @import React;.

Nonetheless, if I add React Native to the consumer app’s Cocoapod — it really works (though you see dozens upon dozens of warnings within the console as a result of every time RN is known as it finds duplicate dependencies).

Potential Static Answer Query

  • The consumer code will not be speaking to RN straight. Given this, I used to be below the impression that having RN and all it is pods delivered within the Framework would work with out bizarre visibility points. Is that this a visibility concern or one thing extra sinister?

Potential Dynamic Answer

I hoped that I may NOT bundle the RN Pods into the framework, delivering solely the bundle.js and Swift interface code within the framework. My understanding was that “use_frameworks!” within the Podfile would accomplish that. I’ve not discovered that to be the case. After I do that, the consumer app behaves precisely as after I go away “use_frameworks!” off. IE: the dependency pods nonetheless look like within the framework.

Potential Dynamic Answer Questions

  • Is there a solution to make this work so the framework would not have the dependency pods and the consumer is answerable for offering them?

Potential Cocoapods Answer

One other potential path is to ship this as a cocoapod as a substitute of a framework. Given the variety of dependencies and the quantity of magic within react_native_pods.rb that I’d lose, this appears impractical.

Potential Cocoapods Options Query

  • Is there a solution to primarily accomplish the identical factor that the use_react_native methodology is doing within the Podfile in a Podspec?

Thanks for any recommendation!

Leave a Reply

Your email address will not be published. Required fields are marked *