-
Notifications
You must be signed in to change notification settings - Fork 564
fix: polluted [RCTBridge currentBridge] #2760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I have signed the CLA! |
|
@Kudo Thank you for looking into this. Here are the two comments that came up:
|
|
@Kudo @alexandrius is this potentially a fix for #2039? |
|
sorry for late to share comment here. i don't like the singleton actually but i didn't find a better way in fabric.
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomView.mm b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomView.mm
index 1f1bdb5..bc0831a 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomView.mm
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomView.mm
@@ -24,10 +24,10 @@ using namespace facebook::react;
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
- auto skManager = [[self skiaManager] skManager];
- // Pass SkManager as a raw pointer to avoid circular dependenciesr
+ // Pass SkManager as a raw pointer to avoid circular dependencies
+ auto skManager = [SkiaManager latestActiveSkManager].get();
[self
- initCommon:skManager.get()
+ initCommon:skManager
factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
return std::make_shared<RNSkiOSView<RNSkia::RNSkDomView>>(context);
}];
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm
index 30f53eb..d77f3b8 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm
@@ -15,7 +15,8 @@
RCT_EXPORT_MODULE(SkiaDomView)
- (SkiaManager *)skiaManager {
- auto bridge = [RCTBridge currentBridge];
+ auto bridge = self.bridge;
+ RCTAssert(bridge, @"Bridge must not be nil.");
auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkiaModule"];
return [skiaModule manager];
}
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.h b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.h
index 8f5457f..07d41dc 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.h
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.h
@@ -16,4 +16,10 @@
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)
jsInvoker;
+#ifdef RCT_NEW_ARCH_ENABLED
+// Fabric components do not have a better way to interact with TurboModules.
+// Workaround to get the SkManager instance from singleton.
++ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager;
+#endif // RCT_NEW_ARCH_ENABLED
+
@end
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm
index 7d3cf59..b32ea39 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm
@@ -8,6 +8,8 @@
#import "RNSkiOSPlatformContext.h"
+static __weak SkiaManager *sharedInstance = nil;
+
@implementation SkiaManager {
std::shared_ptr<RNSkia::RNSkManager> _skManager;
__weak RCTBridge *weakBridge;
@@ -29,6 +31,7 @@
jsInvoker {
self = [super init];
if (self) {
+ sharedInstance = self;
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
if (cxxBridge.runtime) {
@@ -45,4 +48,18 @@
return self;
}
+- (void)dealloc
+{
+ sharedInstance = nil;
+}
+
+#ifdef RCT_NEW_ARCH_ENABLED
++ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager
+{
+ if (sharedInstance != nil) {
+ return [sharedInstance skManager];
+ }
+ return nullptr;
+}
+#endif // RCT_NEW_ARCH_ENABLED
@end
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureView.mm b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureView.mm
index 9bf2f61..b0730f6 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureView.mm
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureView.mm
@@ -24,9 +24,9 @@ using namespace facebook::react;
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
- auto skManager = [[self skiaManager] skManager];
- // Pass SkManager as a raw pointer to avoid circular dependenciesr
- [self initCommon:skManager.get()
+ // Pass SkManager as a raw pointer to avoid circular dependencies
+ auto skManager = [SkiaManager latestActiveSkManager].get();
+ [self initCommon:skManager
factory:[](std::shared_ptr<RNSkia::RNSkPlatformContext> context) {
return std::make_shared<RNSkiOSView<RNSkia::RNSkPictureView>>(
context);
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm
index 8ebccb1..c123db1 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm
@@ -15,7 +15,8 @@
RCT_EXPORT_MODULE(SkiaPictureView)
- (SkiaManager *)skiaManager {
- auto bridge = [RCTBridge currentBridge];
+ auto bridge = self.bridge;
+ RCTAssert(bridge, @"Bridge must not be nil.");
auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkiaModule"];
return [skiaModule manager];
}
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.h b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.h
index 8335d42..c3fb2e2 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.h
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.h
@@ -29,7 +29,6 @@
factory:(std::function<std::shared_ptr<RNSkBaseiOSView>(
std::shared_ptr<RNSkia::RNSkPlatformContext>)>)factory;
- (std::shared_ptr<RNSkBaseiOSView>)impl;
-- (SkiaManager *)skiaManager;
- (void)setDebugMode:(bool)debugMode;
- (void)setOpaque:(bool)opaque;
diff --git a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm
index 8ec714e..2dbe373 100644
--- a/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm
+++ b/node_modules/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm
@@ -48,12 +48,6 @@
_factory = factory;
}
-- (SkiaManager *)skiaManager {
- auto bridge = [RCTBridge currentBridge];
- auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkiaModule"];
- return [skiaModule manager];
-}
-
- (void)willInvalidateModules {
_impl = nullptr;
_manager = nullptr;
@@ -110,7 +104,7 @@
// this flag is only set when the view is inserted and we want to set the
// manager here since the view could be recycled or the app could be
// refreshed and we would have a stale manager then
- _manager = [[self skiaManager] skManager].get();
+ _manager = [SkiaManager latestActiveSkManager].get();
}
}
#endif // RCT_NEW_ARCH_ENABLED
|
not pretty sure for this. i cannot repro this issue previously. |
It doesn't look like the same issue to me. I'm a bit confused with the patch, are you planning to refactor it with a different approach? Should I close this PR? |
|
@alexandrius i would like to keep your pr ongoing since you are the first one raise the issue and propose a solution. so please try to update this pr if my patch makes sense to you. the whole idea of my patch is to move away |
|
@Kudo @wcandillon Updated to @Kudo's patch. Tested works fine |
Kudo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. just having some out-of-sync change and should be good to merge. thanks @alexandrius
Co-authored-by: Kudo Chien <[email protected]>
Co-authored-by: Kudo Chien <[email protected]>
|
🎉 This PR is included in version 1.7.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
--------- Co-authored-by: William Candillon <[email protected]> Co-authored-by: Kudo Chien <[email protected]>
Hello. This PR changes
[RCTBridge currentBridge]to the bridge instance the ViewManager was created. For example react-native-threads creates its own bridge for process separation.Thanks for all amazing work @chrfalch @wcandillon