File tree 8 files changed +34
-16
lines changed
packages/skia/ios/RNSkia-iOS
8 files changed +34
-16
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,10 @@ @implementation SkiaDomView
24
24
25
25
- (instancetype )initWithFrame : (CGRect )frame {
26
26
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 ();
29
29
[self
30
- initCommon: skManager. get ()
30
+ initCommon: skManager
31
31
factory: [](std: :shared_ptr<RNSkia: :RNSkPlatformContext> context) {
32
32
return std::make_shared<RNSkiOSView<RNSkia::RNSkDomView>>(context);
33
33
}];
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ @implementation SkiaDomViewManager
15
15
RCT_EXPORT_MODULE (SkiaDomView)
16
16
17
17
- (SkiaManager *)skiaManager {
18
- auto bridge = [RCTBridge currentBridge ];
18
+ auto bridge = self.bridge ;
19
+ RCTAssert (bridge, @" Bridge must not be nil." );
19
20
auto skiaModule = (RNSkiaModule *)[bridge moduleForName: @" RNSkiaModule" ];
20
21
return [skiaModule manager ];
21
22
}
Original file line number Diff line number Diff line change 16
16
jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)
17
17
jsInvoker;
18
18
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
+
19
25
@end
Original file line number Diff line number Diff line change 8
8
9
9
#import " RNSkiOSPlatformContext.h"
10
10
11
+ static __weak SkiaManager *sharedInstance = nil ;
12
+
11
13
@implementation SkiaManager {
12
14
std::shared_ptr<RNSkia::RNSkManager> _skManager;
13
15
__weak RCTBridge *weakBridge;
@@ -29,6 +31,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
29
31
jsInvoker {
30
32
self = [super init ];
31
33
if (self) {
34
+ sharedInstance = self;
32
35
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
33
36
if (cxxBridge.runtime ) {
34
37
@@ -44,4 +47,18 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
44
47
return self;
45
48
}
46
49
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
47
64
@end
Original file line number Diff line number Diff line change @@ -24,9 +24,9 @@ @implementation SkiaPictureView
24
24
25
25
- (instancetype )initWithFrame : (CGRect )frame {
26
26
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
30
30
factory: [](std: :shared_ptr<RNSkia: :RNSkPlatformContext> context) {
31
31
return std::make_shared<RNSkiOSView<RNSkia::RNSkPictureView>>(
32
32
context);
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ @implementation SkiaPictureViewManager
15
15
RCT_EXPORT_MODULE (SkiaPictureView)
16
16
17
17
- (SkiaManager *)skiaManager {
18
- auto bridge = [RCTBridge currentBridge ];
18
+ auto bridge = self.bridge ;
19
+ RCTAssert (bridge, @" Bridge must not be nil." );
19
20
auto skiaModule = (RNSkiaModule *)[bridge moduleForName: @" RNSkiaModule" ];
20
21
return [skiaModule manager ];
21
22
}
Original file line number Diff line number Diff line change 29
29
factory : (std::function<std::shared_ptr<RNSkBaseiOSView>(
30
30
std::shared_ptr<RNSkia::RNSkPlatformContext>)>)factory;
31
31
- (std::shared_ptr<RNSkBaseiOSView>)impl ;
32
- - (SkiaManager *)skiaManager ;
33
32
34
33
- (void )setDebugMode : (bool )debugMode ;
35
34
- (void )setOpaque : (bool )opaque ;
Original file line number Diff line number Diff line change @@ -48,12 +48,6 @@ - (void)initCommon:(RNSkia::RNSkManager *)manager
48
48
_factory = factory;
49
49
}
50
50
51
- - (SkiaManager *)skiaManager {
52
- auto bridge = [RCTBridge currentBridge ];
53
- auto skiaModule = (RNSkiaModule *)[bridge moduleForName: @" RNSkiaModule" ];
54
- return [skiaModule manager ];
55
- }
56
-
57
51
- (void )willInvalidateModules {
58
52
_impl = nullptr ;
59
53
_manager = nullptr ;
@@ -114,7 +108,7 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
114
108
// this flag is only set when the view is inserted and we want to set the
115
109
// manager here since the view could be recycled or the app could be
116
110
// refreshed and we would have a stale manager then
117
- _manager = [[ self skiaManager ] skManager ].get ();
111
+ _manager = [SkiaManager latestActiveSkManager ].get ();
118
112
}
119
113
}
120
114
#endif // RCT_NEW_ARCH_ENABLED
You can’t perform that action at this time.
0 commit comments