-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Native side not loading with custom AppDelegate.swift #4631
Comments
Hey @danielRChildrens, thanks for reporting this issue. Currently, our initialization flow for iOS assumes that Please let me know if any of the approaches below works for you:
-class AppDelegate: UIResponder, UIApplicationDelegate {
+class AppDelegate: RCTAppDelegate, UIResponder, UIApplicationDelegate {
|
@tomekzaw Could you please give more information about the approach 2? Tried to make my AppDelegate.swift to implement |
@tapz I'm a Swift beginner so I don't think I can help much in this case. Basically, you need to call |
@tomekzaw |
@tomekzaw Ok, I'll try to add it to as early as possible in the app initialization. |
@tapz We're currently working on a better solution so hopefully Reanimated 3.4.0 will no longer use this mechanism. |
The problem is that I don't know how to call
or if I remove
Probably have to write some kind of Objective-c bridge to make the call. |
Yup, |
I created a bridge, but now the app crashes to this:
REAnimatedBridge.h
REAnimatedBridge.mpp
MyApp-Bridging-Header.m
AppDelegate.swift
rainit probably could be static, so there would be no need to create an instance of |
@tapz What do you mean by "I created a bridge"? You need to pass the same instance of bridge which has already been created by React Native. |
@tomekzaw Since I'm not using RCTAppDelegate, I need to create the bridge myself.
|
@tapz try below code. It is work for me. import UIKit
import React
class RNBaseViewController: UIViewController {
init(moduleName: String, initialProperties: [AnyHashable : Any]? = nil) {
hacker = RNObjcHacker()
let bridge = RCTBridge(delegate: hacker, launchOptions: nil)!
rootView = RCTRootView(bridge: bridge, moduleName: moduleName, initialProperties: initialProperties)
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let hacker: RNObjcHacker
let rootView: RCTRootView
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
addRCTRootView()
}
func addRCTRootView() {
rootView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(rootView)
NSLayoutConstraint.activate([
rootView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
rootView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
rootView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
rootView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
])
}
} // RNObjcHacker.h file
#import <Foundation/Foundation.h>
#import <React/RCTBridge.h>
NS_ASSUME_NONNULL_BEGIN
@interface RNObjcHacker : NSObject<RCTBridgeDelegate>
@end
NS_ASSUME_NONNULL_END
// RNObjcHacker.mm file
#import "RNObjcHacker.h"
#import <React/RCTRuntimeExecutorFromBridge.h>
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <RCTAppSetupUtils.h>
#import <RNReanimated/REAInitializer.h>
#import <React/RCTBundleURLProvider.h>
@interface RNObjcHacker () <RCTCxxBridgeDelegate> {
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
}
@end
@implementation RNObjcHacker
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
- (BOOL)runtimeSchedulerEnabled
{
return YES;
}
#pragma mark - RCTCxxBridgeDelegate
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
reanimated::REAInitializer(bridge);
if (self.runtimeSchedulerEnabled) {
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
}
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
}
@end |
@tomekzaw I updated from 3.3.0 to 3.4.1 and now
|
Does not seem to require the |
yes, you no longer need to call REAInitializer |
Description
I am receiving the following error after converting the AppDelegate.mm to AppDelegate.swift:
Error: [Reanimated] The native part of Reanimated doesn't seem to be initialized.
AppDelegate.swift
Notes:
Steps to reproduce
I have two Branches as follows:
When both branches are merged (swift-appdelegate-reanimated), getting Swift AppDelegate With Reanimated, the iOS build works, but when the app is launched I get the error:
Snack or a link to a repository
https://github.com/danielRChildrens/SwiftReanimated/tree/swift-appdelegate-reanimated
Reanimated version
3.3.0
React Native version
0.71.6
Platforms
iOS
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Paper (Old Architecture)
Build type
Debug mode
Device
iOS simulator
Device model
iOS 16 iphone 14
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: