question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reanimated module is not initialized when a class that implements the RCTBridgeDelegate Protocol is used

See original GitHub issue

Description

Reanimated module is not initialized when a class that implements the RCTBridgeDelegate Protocol is used (e.g. when dependency injections are needed/brownfield apps). App throws undefined is not an object (evaluating 'InnerNativeModule.installCoreFunctions')

When a class that implements the RCTBridgeDelegate Protocol is used, jsExecutorFactoryForBridge in UIResponder+Reanimated.mm is never called.

My understanding is this happens because this condition

    if ([self.delegate conformsToProtocol:@protocol(RCTCxxBridgeDelegate)]) {

in RCTCxxBridge.mm is not satisfied and [cxxDelegate jsExecutorFactoryForBridge:self] is not called here.

Expected behavior

Reanimated module is initialized.

Actual behavior & steps to reproduce

Module is not initialized and App crashes with undefined is not an object (evaluating 'InnerNativeModule.installCoreFunctions'). Please see link to the fork of reanimated 2 playground below to reporoduce

Snack or minimal code example

fork of reanimated 2 playground that demonstrates the issue (branch name delegate_bridge)

Package versions

  • React Native: 0.65.1
  • React Native Reanimated: 2.3.0-beta.1 (also tested on 2.3.1, 2.2.4)
  • NodeJS: 14.18.0
  • Xcode: 13.1
  • Java & Gradle: not relevant

Affected platforms

  • Android
  • iOS
  • Web

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
dov11commented, Jan 4, 2022

The module will autoinstall if the class that implements the RCTBridgeDelegate Protocol is a subclass of UIResponder. E.g. in the example fork above:

ClassThatImplementsRCTBridgeDelegate : UIResponder

Alternatively, Reanimated can be patched with patch-package:

diff --git a/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.h b/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.h
index 3ee3797..0805b0d 100644
--- a/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.h
+++ b/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.h
@@ -3,7 +3,7 @@
 
 #ifndef DONT_AUTOINSTALL_REANIMATED
 
-@interface UIResponder (Reanimated) <RCTCxxBridgeDelegate>
+@interface NSObject (Reanimated) <RCTCxxBridgeDelegate>
 
 @end
 
diff --git a/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.mm b/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.mm
index 28c9262..a815e12 100644
--- a/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.mm
+++ b/node_modules/react-native-reanimated/ios/native/UIResponder+Reanimated.mm
@@ -15,7 +15,7 @@
 
 #ifndef DONT_AUTOINSTALL_REANIMATED
 
-@implementation UIResponder (Reanimated)
+@implementation NSObject (Reanimated)
 - (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
 {
   const auto installer = reanimated::REAJSIExecutorRuntimeInstaller(bridge, NULL);
1reaction
adrianhacommented, Aug 23, 2022

just created new repo (init with RN 0.69 + Reanimated 2.9.1) to repro this issue:

  • main: bridge initiated in AppDelegate –> Reanimated works fine
  • custom-bridge: bridge initiated outside of AppDelegate –> throws TypeError: undefined is not an object (evaluating 'this.InnerNativeModule.installCoreFunctions')
Read more comments on GitHub >

github_iconTop Results From Across the Web

module failed to load due to an error and `appregistry ...
Invariant Violation: "RestApp" has not been registered. This can happen if: Metro (the local dev server) is run from the wrong folder.
Read more >
undefined is not an object 'installCoreFunctions' react-native ...
I suspect something about the JSI module not having the VM reference early on. Make sure to init react root view using the...
Read more >
Installation | React Native Reanimated - Software Mansion
Reanimated 2 is primarily built in C++ using Turbo Modules infrastructure which is not yet completely deployed in React Native (specifically on Android)....
Read more >
Dependency Injection in React Native modules-React Native
Initialise a class that implements RCTBridgeDelegate // Be warned, ... answer this question // We must return an array of initialised Modules //...
Read more >
React Native Reanimated 2 - a webinar by Krzysztof Magiera
Following the recent release of the new open-source library - Reanimated 2, we wanted to share with the community more information about ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found