react-native-reanimated: Native side not loading with custom AppDelegate.swift
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
import Foundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var bridge: RCTBridge!
func application(_ application:UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey : Any]?) -> Bool {
let jsCodeLocation: URL
jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "DigitalFrontDoor", initialProperties: nil, launchOptions: launchOptions)
let rootViewController = UIViewController()
rootViewController.view = rootView
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
return true
}
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
func concurrentRootEnabled() -> Bool {
return true
}
}
Notes:
- The iOS build is completing successfully
- Android is working as expected
- I have tried removing the Pods, node_modules, build folders and reinstalling everything.
- I have tried restarting my computer
- Converting the AppDelegate to swift works without Reanimated
- I have followed this post for the AppDelegate swift migration (https://ospfranco.com/post/2021/07/31/migrate-rn-appdelegate-to-swift/)
Steps to reproduce
I have two Branches as follows:
- Branch 1 (reanimated): Regular AppDelegate with Reanimated, In this branch everything works as expected in both platforms
- Branch 2 (swift-app-delegate): Swift AppDelegate without Reanimated, In this branch everything works as expected in both platforms
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
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (6 by maintainers)
Does not seem to require the
REAInitializer
call anymore…Hey @danielRChildrens, thanks for reporting this issue.
Currently, our initialization flow for iOS assumes that
AppDelegate
extendsRCTAppDelegate
. We swizzlejsExecutorFactoryForBridge
method in order to callreanimated::REAInitializer(bridge)
at the early stage of app startup (seeRCTAppDelegate+Reanimated.mm
).Please let me know if any of the approaches below works for you:
AppDelegate
so that it extendsRCTAppDelegate
jsExecutorFactoryForBridge
and manually callreanimated::REAInitializer(bridge)