From 81a7df0001774088f940b6ed45f2cbc9f2250de5 Mon Sep 17 00:00:00 2001 From: Krzysztof Piaskowy Date: Thu, 9 May 2024 08:46:35 +0200 Subject: [PATCH] Get right bridge (#2886) ## Description This PR fixes getting access to right bridge, because `currentBridge` method can return invalid pointer when more than one instance of react exists in the application. Same changes we made in the Reanimated - https://github.com/software-mansion/react-native-reanimated/pull/5953 ## Test plan I tested FabricExample on iOS with/without bridge, after startup and after reload, and it seems to work. --- apple/RNGestureHandlerModule.mm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apple/RNGestureHandlerModule.mm b/apple/RNGestureHandlerModule.mm index d36fcf4e3f..9deb831812 100644 --- a/apple/RNGestureHandlerModule.mm +++ b/apple/RNGestureHandlerModule.mm @@ -53,7 +53,6 @@ @implementation RNGestureHandlerModule { #ifdef RCT_NEW_ARCH_ENABLED @synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED; -@synthesize bridge = _bridge; @synthesize dispatchToJSThread = _dispatchToJSThread; #endif // RCT_NEW_ARCH_ENABLED @@ -133,14 +132,14 @@ - (void)setBridge:(RCTBridge *)bridge RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) { dispatch_block_t block = ^{ - RCTCxxBridge *cxxBridge = (RCTCxxBridge *)[RCTBridge currentBridge]; + RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge; auto runtime = (jsi::Runtime *)cxxBridge.runtime; decorateRuntime(*runtime); }; if (_dispatchToJSThread) { _dispatchToJSThread(block); } else { - [[RCTBridge currentBridge] dispatchBlock:block queue:RCTJSThread]; + [self.bridge dispatchBlock:block queue:RCTJSThread]; } return @true;