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.

iOS: All reanimated gestures sometimes don't work after app launch

See original GitHub issue

Description

Sometimes all reanimated gestures don’t work after app launch, including PanGestureHandler onGestureEvent and Animated.ScrollView onScroll.

Expected behavior

Everything always works.

Actual behavior & steps to reproduce

Sometimes on app launch nothing from reanimated works.

Snack or minimal code example

Not sure what to add here because we have lots of reanimated code.

      return (
        <PanGestureHandler
          enabled={isActive}
          activeOffsetX={ACTIVE_OFFSET_X}
          onGestureEvent={onGestureEvent} // this is never called
        >
          <Animated.View style={[styles.container, currentItemAnimatedStyle]}>
            {renderItem(item, index, currentIndex, isActive)}
            <Animated.View
              pointerEvents="none"
              style={[styles.likeLabel, likeLabelStyle]}
            >
              <Image source={Images.swiperActions.likeBanner} />
            </Animated.View>
            <Animated.View
              pointerEvents="none"
              style={[styles.dislikeLabel, dislikeLabelStyle]}
            >
              <Image source={Images.swiperActions.dislikeBanner} />
            </Animated.View>
          </Animated.View>
        </PanGestureHandler>
      );

Package versions

  • React Native: 0.63.4 - 0.66.1
  • React Native Reanimated: 2.2.2 - 2.3.0-beta.2
  • NodeJS: v14.17.6
  • Xcode: 12.5.1

Affected platforms

  • Android
  • iOS
  • Web

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
TexxUkrcommented, Nov 1, 2021

Having similar issue on ios only and only after JS thread restart when different js modules (still using reanimated2 and pan gesture handler) are loaded next time. useAnimatedGestureHandler does not call anything but a simple callback function as onGestureEvent works fine. valid for 2.2.0 and 2.2.4…

0reactions
gentleecommented, Jan 28, 2022

@piaskowyk we used patch to fix that, i guess taken from some PR, and it helped.

If this PR was merged I guess latest version should also fix it, but I didn’t test it.

react-native-reanimated+2.2.4.patch

diff --git a/node_modules/react-native-reanimated/ios/REAEventDispatcher.m b/node_modules/react-native-reanimated/ios/REAEventDispatcher.m
index f2866e0..a310c8f 100644
--- a/node_modules/react-native-reanimated/ios/REAEventDispatcher.m
+++ b/node_modules/react-native-reanimated/ios/REAEventDispatcher.m
@@ -7,7 +7,7 @@
 
 - (void)sendEvent:(id<RCTEvent>)event
 {
-  [[_bridge_reanimated moduleForName:@"ReanimatedModule"] eventDispatcherWillDispatchEvent:event];
+  [[[self bridge] moduleForName:@"ReanimatedModule"] eventDispatcherWillDispatchEvent:event];
   [super sendEvent:event];
 }
 
diff --git a/node_modules/react-native-reanimated/ios/REAModule.h b/node_modules/react-native-reanimated/ios/REAModule.h
index 85ac1fb..e9a225f 100644
--- a/node_modules/react-native-reanimated/ios/REAModule.h
+++ b/node_modules/react-native-reanimated/ios/REAModule.h
@@ -7,8 +7,6 @@
 
 #import "REAValueNode.h"
 
-extern RCTBridge *_bridge_reanimated;
-
 @interface REAModule : RCTEventEmitter <RCTBridgeModule, RCTEventDispatcherObserver, RCTUIManagerObserver>
 
 @property (nonatomic, readonly) REANodesManager *nodesManager;
diff --git a/node_modules/react-native-reanimated/ios/REAModule.m b/node_modules/react-native-reanimated/ios/REAModule.m
index f64ffc0..b1abf0e 100644
--- a/node_modules/react-native-reanimated/ios/REAModule.m
+++ b/node_modules/react-native-reanimated/ios/REAModule.m
@@ -6,8 +6,6 @@
 
 typedef void (^AnimatedOperation)(REANodesManager *nodesManager);
 
-RCTBridge *_bridge_reanimated = nil;
-
 @implementation REAModule
 {
   NSMutableArray<AnimatedOperation> *_operations;
@@ -18,7 +16,6 @@ RCT_EXPORT_MODULE(ReanimatedModule);
 
 - (void)invalidate
 {
-  _bridge_reanimated = nil;
   _transitionManager = nil;
   [_nodesManager invalidate];
   [self.bridge.uiManager.observerCoordinator removeObserver:self];
diff --git a/node_modules/react-native-reanimated/ios/native/NativeProxy.h b/node_modules/react-native-reanimated/ios/native/NativeProxy.h
index bfa2513..dabc86e 100644
--- a/node_modules/react-native-reanimated/ios/native/NativeProxy.h
+++ b/node_modules/react-native-reanimated/ios/native/NativeProxy.h
@@ -6,7 +6,7 @@
 
 namespace reanimated {
  
-std::shared_ptr<reanimated::NativeReanimatedModule> createReanimatedModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
+std::shared_ptr<reanimated::NativeReanimatedModule> createReanimatedModule(RCTBridge *bridge, std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
 
 }
 
diff --git a/node_modules/react-native-reanimated/ios/native/NativeProxy.mm b/node_modules/react-native-reanimated/ios/native/NativeProxy.mm
index 682093f..fa3351e 100644
--- a/node_modules/react-native-reanimated/ios/native/NativeProxy.mm
+++ b/node_modules/react-native-reanimated/ios/native/NativeProxy.mm
@@ -84,8 +84,7 @@ static id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &v
   throw std::runtime_error("Unsupported jsi::jsi::Value kind");
 }
 
-std::shared_ptr<NativeReanimatedModule> createReanimatedModule(std::shared_ptr<CallInvoker> jsInvoker) {
-  RCTBridge *bridge = _bridge_reanimated;
+std::shared_ptr<NativeReanimatedModule> createReanimatedModule(RCTBridge *bridge, std::shared_ptr<CallInvoker> jsInvoker) {
   REAModule *reanimatedModule = [bridge moduleForClass:[REAModule class]];
 
   auto propUpdater = [reanimatedModule](jsi::Runtime &rt, int viewTag, const jsi::Value& viewName, const jsi::Object &props) -> void {
diff --git a/node_modules/react-native-reanimated/ios/native/REAInitializer.mm b/node_modules/react-native-reanimated/ios/native/REAInitializer.mm
index 2f31b3c..5a35c74 100644
--- a/node_modules/react-native-reanimated/ios/native/REAInitializer.mm
+++ b/node_modules/react-native-reanimated/ios/native/REAInitializer.mm
@@ -28,16 +28,15 @@ JSIExecutor::RuntimeInstaller REAJSIExecutorRuntimeInstaller(
     [eventDispatcher setBridge:bridge];
     #endif
     [bridge updateModuleWithInstance:eventDispatcher];
-     _bridge_reanimated = bridge;
     const auto runtimeInstaller = [bridge, runtimeInstallerToWrap](facebook::jsi::Runtime &runtime) {
       if (!bridge) {
         return;
       }
 #if RNVERSION >= 63
-    auto reanimatedModule = reanimated::createReanimatedModule(bridge.jsCallInvoker);
+    auto reanimatedModule = reanimated::createReanimatedModule(bridge, bridge.jsCallInvoker);
 #else
     auto callInvoker = std::make_shared<react::BridgeJSCallInvoker>(bridge.reactInstance);
-    auto reanimatedModule = reanimated::createReanimatedModule(callInvoker);
+    auto reanimatedModule = reanimated::createReanimatedModule(bridge, callInvoker);
 #endif
     runtime.global().setProperty(runtime,
                                  jsi::PropNameID::forAscii(runtime, "__reanimatedModuleProxy"),

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn on and practice VoiceOver on iPhone - Apple Support
Learn and practice VoiceOver gestures · Go to Settings > Accessibility > VoiceOver. · Turn on VoiceOver, tap VoiceOver Practice, then double-tap to...
Read more >
onGestureEvent not being called when I try to move a box with ...
I've started react native project from scratch, installed react reanimated 1. I've pushed the repository: ...
Read more >
Troubleshooting | Stream Chat - React Native SDK Docs
When you return to the original screen you need to reset the thread to ensure it is not being set on the messages...
Read more >
React Navigation 6.0
Let's talk about the highlights of this release in this blog post. ... While this works for a lot of apps, apps with...
Read more >
Reanimating Your React Native Experience | blog {callstack}
event we could map gesture state to the position of the box and make this whole interaction run on UI thread with useNativeDriver...
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