-
ObjectiveMy client has an iOS Swift application. In order to do so, we are trying to create an xcFramework that embeds all RN dependencies. ProblemI solved several problems, but the integration of When I launch my app, I have the following error : The documentation does not specify a clear way to achieve this goal
My setupDependencies:
How I create my RCTRootView in my xcFramework @implementation ReactNativeMyApp
- (UIViewController *)getApp {
NSURL *url = [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios"];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:url moduleName:@"AuthenticationModule" initialProperties:@{} launchOptions:@{}];
UIViewController *vc = [[UIViewController alloc] init];
vc.view = rootView;
return vc;
}
@end How I display the RTCRootView in my app This is done in a random import UIKit
import my_xcframework
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func startAuthenticationModule(_ sender: Any) {
let MyRNApp = ReactNativeMyApp()
let vc = MyRNApp.getApp()
guard let vc = vc else {
assertionFailure("No ViewController")
return
}
vc.view.frame = UIScreen.main.bounds
present(vc, animated: false)
}
} QuestionI have found this issue, but it does not fix my issue as i want the bridge to be initialized inside the xcFramework. I also tried the Do you have any tips to help me with this issue? Thank you 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I come back with the solution we found. The main problem is: how to execute the installation code that is normally called automatically? I'm talking about this: react-native-reanimated/ios/native/UIResponder+Reanimated.mm Lines 20 to 30 in 1134b95 Here is the solution we found : ##
# HEADER FILE
##
#ifndef MyBridgeManager_h
#define MyBridgeManager_h
#import <React/RCTBridgeDelegate.h>
# We create our own BridgeDelete
@interface MyBridgeManager : NSObject <RCTBridgeDelegate>
@end
#endif /* MyBridgeManager_h */
##
# IMPLEMENTATION
##
#import "MyBridgeManager.h"
#import <Foundation/Foundation.h>
#import <React/RCTBundleURLProvider.h>
#import <RNReanimated/REAInitializer.h>
#import <RNReanimated/REAUIManager.h>
#import <RNReanimated/UIResponder+Reanimated.h>
#if __has_include(<reacthermes/HermesExecutorFactory.h>)
#import <reacthermes/HermesExecutorFactory.h>
typedef HermesExecutorFactory ExecutorFactory;
#elif __has_include(<React/HermesExecutorFactory.h>)
#import <React/HermesExecutorFactory.h>
typedef HermesExecutorFactory ExecutorFactory;
#else
#import <React/JSCExecutorFactory.h>
typedef JSCExecutorFactory ExecutorFactory;
#endif
#import <React/RCTCxxBridgeDelegate.h>
@interface MyBridgeManager () <RCTCxxBridgeDelegate>
@end
@implementation MyBridgeManager
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
// Important for react-native-reanimated : installation code
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
const auto installer = reanimated::REAJSIExecutorRuntimeInstaller(bridge, NULL);
#if REACT_NATIVE_MINOR_VERSION >= 64
// installs globals such as console, nativePerformanceNow, etc.
return std::make_unique<ExecutorFactory>(RCTJSIExecutorRuntimeInstaller(installer));
#else
return std::make_unique<ExecutorFactory>(installer);
#endif
} And this is how then we instantiate the - (UIViewController *)getApp {
RNMeeticBridgeManager *bridgeManager = [RNMeeticBridgeManager alloc];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:[[RCTBridge alloc] initWithDelegate:bridgeManager launchOptions:@{}] moduleName:@"AuthenticationModule" initialProperties:@{}];
UIViewController *vc = [[UIViewController alloc] init];
vc.view = rootView;
return vc;
} To be honest, I do not understand everything, especially the I have the feeling that it should be done in: react-native-reanimated/ios/REAModule.mm Lines 238 to 241 in 1134b95 Is there any reason why this method is not implemented? Any challenges on which I can help? |
Beta Was this translation helpful? Give feedback.
-
Thank you @taboulot! I've been wrestling to integrate reanimated in my brownfield app, and your comment helped lead me to a solution that worked for our setup. Our brownfield app has an unusual setup where our native code lives up a few directory levels from the react native code. Also, we're adding Here are the steps that worked:
Thanks again for sharing your knowledge! Hope these notes help someone in the future 💟 |
Beta Was this translation helpful? Give feedback.
I come back with the solution we found.
The main problem is: how to execute the installation code that is normally called automatically?
I'm talking about this:
react-native-reanimated/ios/native/UIResponder+Reanimated.mm
Lines 20 to 30 in 1134b95