From cf1f6181fddb871f2b638fb0b1dd5668ea9536f2 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Wed, 4 Dec 2024 17:50:46 +0100 Subject: [PATCH] fix: brownfield integration (#6774) ## Summary In brownfield, ` // we need only one instance because SurfacePresenter is the same during the application lifetime` is false since you can destroy RN and create it again. ## Test plan Run Reanimated in brownfield and try to create and destroy the whole RN a couple of times. --- .../apple/Fabric/REAInitializerRCTFabricSurface.h | 2 +- .../apple/reanimated/apple/REAModule.mm | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/react-native-reanimated/apple/reanimated/apple/Fabric/REAInitializerRCTFabricSurface.h b/packages/react-native-reanimated/apple/reanimated/apple/Fabric/REAInitializerRCTFabricSurface.h index bd8143b8a55..c27c2106790 100644 --- a/packages/react-native-reanimated/apple/reanimated/apple/Fabric/REAInitializerRCTFabricSurface.h +++ b/packages/react-native-reanimated/apple/reanimated/apple/Fabric/REAInitializerRCTFabricSurface.h @@ -5,7 +5,7 @@ @interface REAInitializerRCTFabricSurface : RCTFabricSurface -@property REAModule *reaModule; +@property __weak REAModule *reaModule; @end diff --git a/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm b/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm index 5ee5b74c4f7..9b48d8557f2 100644 --- a/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm +++ b/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm @@ -193,9 +193,10 @@ - (void)setBridge:(RCTBridge *)bridge - (void)setReaSurfacePresenter { - if (reaSurface == nil) { - // we need only one instance because SurfacePresenter is the same during the application lifetime - reaSurface = [[REAInitializerRCTFabricSurface alloc] init]; + if (_surfacePresenter && ![_surfacePresenter surfaceForRootTag:reaSurface.rootTag]) { + if (!reaSurface) { + reaSurface = [[REAInitializerRCTFabricSurface alloc] init]; + } [_surfacePresenter registerSurface:reaSurface]; } reaSurface.reaModule = self;