File tree Expand file tree Collapse file tree 8 files changed +34
-16
lines changed
Expand file tree Collapse file tree 8 files changed +34
-16
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,10 @@ @implementation SkiaDomView
2424
2525- (instancetype )initWithFrame : (CGRect)frame {
2626 if (self = [super initWithFrame: frame]) {
27- auto skManager = [[ self skiaManager ] skManager ];
28- // Pass SkManager as a raw pointer to avoid circular dependenciesr
27+ // Pass SkManager as a raw pointer to avoid circular dependencies
28+ auto skManager = [SkiaManager latestActiveSkManager ]. get ();
2929 [self
30- initCommon: skManager. get ()
30+ initCommon: skManager
3131 factory: [](std: :shared_ptr<RNSkia: :RNSkPlatformContext> context) {
3232 return std::make_shared<RNSkiOSView<RNSkia::RNSkDomView>>(context);
3333 }];
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ @implementation SkiaDomViewManager
1515RCT_EXPORT_MODULE (SkiaDomView)
1616
1717- (SkiaManager *)skiaManager {
18- auto bridge = [RCTBridge currentBridge ];
18+ auto bridge = self.bridge ;
19+ RCTAssert (bridge, @" Bridge must not be nil." );
1920 auto skiaModule = (RNSkiaModule *)[bridge moduleForName: @" RNSkiaModule" ];
2021 return [skiaModule manager ];
2122}
Original file line number Diff line number Diff line change 1616 jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)
1717 jsInvoker;
1818
19+ #ifdef RCT_NEW_ARCH_ENABLED
20+ // Fabric components do not have a better way to interact with TurboModules.
21+ // Workaround to get the SkManager instance from singleton.
22+ + (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager ;
23+ #endif // RCT_NEW_ARCH_ENABLED
24+
1925@end
Original file line number Diff line number Diff line change 88
99#import " RNSkiOSPlatformContext.h"
1010
11+ static __weak SkiaManager *sharedInstance = nil ;
12+
1113@implementation SkiaManager {
1214 std::shared_ptr<RNSkia::RNSkManager> _skManager;
1315 __weak RCTBridge *weakBridge;
@@ -29,6 +31,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
2931 jsInvoker {
3032 self = [super init ];
3133 if (self) {
34+ sharedInstance = self;
3235 RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
3336 if (cxxBridge.runtime ) {
3437
@@ -44,4 +47,18 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
4447 return self;
4548}
4649
50+ - (void )dealloc
51+ {
52+ sharedInstance = nil ;
53+ }
54+
55+ #ifdef RCT_NEW_ARCH_ENABLED
56+ + (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager
57+ {
58+ if (sharedInstance != nil ) {
59+ return [sharedInstance skManager ];
60+ }
61+ return nullptr ;
62+ }
63+ #endif // RCT_NEW_ARCH_ENABLED
4764@end
Original file line number Diff line number Diff line change @@ -24,9 +24,9 @@ @implementation SkiaPictureView
2424
2525- (instancetype )initWithFrame : (CGRect)frame {
2626 if (self = [super initWithFrame: frame]) {
27- auto skManager = [[ self skiaManager ] skManager ];
28- // Pass SkManager as a raw pointer to avoid circular dependenciesr
29- [self initCommon: skManager. get ()
27+ // Pass SkManager as a raw pointer to avoid circular dependencies
28+ auto skManager = [SkiaManager latestActiveSkManager ]. get ();
29+ [self initCommon: skManager
3030 factory: [](std: :shared_ptr<RNSkia: :RNSkPlatformContext> context) {
3131 return std::make_shared<RNSkiOSView<RNSkia::RNSkPictureView>>(
3232 context);
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ @implementation SkiaPictureViewManager
1515RCT_EXPORT_MODULE (SkiaPictureView)
1616
1717- (SkiaManager *)skiaManager {
18- auto bridge = [RCTBridge currentBridge ];
18+ auto bridge = self.bridge ;
19+ RCTAssert (bridge, @" Bridge must not be nil." );
1920 auto skiaModule = (RNSkiaModule *)[bridge moduleForName: @" RNSkiaModule" ];
2021 return [skiaModule manager ];
2122}
Original file line number Diff line number Diff line change 2929 factory : (std::function<std::shared_ptr<RNSkBaseiOSView>(
3030 std::shared_ptr<RNSkia::RNSkPlatformContext>)>)factory;
3131- (std::shared_ptr<RNSkBaseiOSView>)impl ;
32- - (SkiaManager *)skiaManager ;
3332
3433- (void )setDebugMode : (bool )debugMode ;
3534- (void )setOpaque : (bool )opaque ;
Original file line number Diff line number Diff line change @@ -48,12 +48,6 @@ - (void)initCommon:(RNSkia::RNSkManager *)manager
4848 _factory = factory;
4949}
5050
51- - (SkiaManager *)skiaManager {
52- auto bridge = [RCTBridge currentBridge ];
53- auto skiaModule = (RNSkiaModule *)[bridge moduleForName: @" RNSkiaModule" ];
54- return [skiaModule manager ];
55- }
56-
5751- (void )willInvalidateModules {
5852 _impl = nullptr ;
5953 _manager = nullptr ;
@@ -114,7 +108,7 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
114108 // this flag is only set when the view is inserted and we want to set the
115109 // manager here since the view could be recycled or the app could be
116110 // refreshed and we would have a stale manager then
117- _manager = [[ self skiaManager ] skManager ].get ();
111+ _manager = [SkiaManager latestActiveSkManager ].get ();
118112 }
119113}
120114#endif // RCT_NEW_ARCH_ENABLED
You can’t perform that action at this time.
0 commit comments