From 58db0321757b5ec04106731df6aab8f48b4c7496 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Fri, 16 Feb 2024 22:31:17 +0800 Subject: [PATCH 1/2] Fix bridgeless support on iOS --- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h | 5 ++--- package/ios/RNSkia-iOS/SkiaManager.h | 2 +- package/ios/RNSkia-iOS/SkiaManager.mm | 8 +++----- package/ios/RNSkiaModule.mm | 8 +++++++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h b/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h index 1723ec0dac..e9dc2e0864 100644 --- a/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +++ b/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h @@ -2,7 +2,6 @@ #import #import -#import #include #include @@ -30,8 +29,8 @@ static void handleNotification(CFNotificationCenterRef center, void *observer, class RNSkiOSPlatformContext : public RNSkPlatformContext { public: - RNSkiOSPlatformContext(jsi::Runtime *runtime, RCTBridge *bridge) - : RNSkPlatformContext(runtime, bridge.jsCallInvoker, + RNSkiOSPlatformContext(jsi::Runtime *runtime, RCTBridge *bridge, std::shared_ptr jsCallInvoker) + : RNSkPlatformContext(runtime, jsCallInvoker, [[UIScreen mainScreen] scale]) { // We need to make sure we invalidate when modules are freed diff --git a/package/ios/RNSkia-iOS/SkiaManager.h b/package/ios/RNSkia-iOS/SkiaManager.h index b559eb6ef4..77ccd82bc9 100644 --- a/package/ios/RNSkia-iOS/SkiaManager.h +++ b/package/ios/RNSkia-iOS/SkiaManager.h @@ -12,6 +12,6 @@ - (void)invalidate; -- (instancetype)initWithBridge:(RCTBridge *)bridge; +- (instancetype)initWithBridge:(RCTBridge *)bridge jsInvoker:(std::shared_ptr)jsInvoker; @end diff --git a/package/ios/RNSkia-iOS/SkiaManager.mm b/package/ios/RNSkia-iOS/SkiaManager.mm index 8c3d291dc7..06938f2d0f 100644 --- a/package/ios/RNSkia-iOS/SkiaManager.mm +++ b/package/ios/RNSkia-iOS/SkiaManager.mm @@ -6,8 +6,6 @@ #import #import -#import - #import "RNSkiOSPlatformContext.h" @implementation SkiaManager { @@ -26,7 +24,7 @@ - (void)invalidate { _skManager = nullptr; } -- (instancetype)initWithBridge:(RCTBridge *)bridge { +- (instancetype)initWithBridge:(RCTBridge *)bridge jsInvoker:(std::shared_ptr)jsInvoker { self = [super init]; if (self) { RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge; @@ -37,8 +35,8 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge { // Create the RNSkiaManager (cross platform) _skManager = std::make_shared( - jsRuntime, bridge.jsCallInvoker, - std::make_shared(jsRuntime, bridge)); + jsRuntime, jsInvoker, + std::make_shared(jsRuntime, bridge, jsInvoker)); } } return self; diff --git a/package/ios/RNSkiaModule.mm b/package/ios/RNSkiaModule.mm index fe7f2a4eb4..591439f87b 100644 --- a/package/ios/RNSkiaModule.mm +++ b/package/ios/RNSkiaModule.mm @@ -1,9 +1,11 @@ #import "RNSkiaModule.h" #import +#import @implementation RNSkiaModule { SkiaManager *skiaManager; + std::shared_ptr jsInvoker; } RCT_EXPORT_MODULE() @@ -33,13 +35,17 @@ - (void)invalidate { return @true; } RCTBridge *bridge = [RCTBridge currentBridge]; - skiaManager = [[SkiaManager alloc] initWithBridge:bridge]; + if (!jsInvoker) { + jsInvoker = bridge.jsCallInvoker; + } + skiaManager = [[SkiaManager alloc] initWithBridge:bridge jsInvoker:jsInvoker]; return @true; } #ifdef RCT_NEW_ARCH_ENABLED - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { + jsInvoker = params.jsInvoker; return std::make_shared(params); } #endif From e21cccfe18f4a977828717a540d304761cc96b0b Mon Sep 17 00:00:00 2001 From: William Candillon Date: Fri, 16 Feb 2024 20:03:02 +0100 Subject: [PATCH 2/2] :green_heart: --- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h | 4 +++- package/ios/RNSkia-iOS/SkiaManager.h | 4 +++- package/ios/RNSkia-iOS/SkiaManager.mm | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h b/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h index e9dc2e0864..2982d80a0f 100644 --- a/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +++ b/package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h @@ -29,7 +29,9 @@ static void handleNotification(CFNotificationCenterRef center, void *observer, class RNSkiOSPlatformContext : public RNSkPlatformContext { public: - RNSkiOSPlatformContext(jsi::Runtime *runtime, RCTBridge *bridge, std::shared_ptr jsCallInvoker) + RNSkiOSPlatformContext( + jsi::Runtime *runtime, RCTBridge *bridge, + std::shared_ptr jsCallInvoker) : RNSkPlatformContext(runtime, jsCallInvoker, [[UIScreen mainScreen] scale]) { diff --git a/package/ios/RNSkia-iOS/SkiaManager.h b/package/ios/RNSkia-iOS/SkiaManager.h index 77ccd82bc9..a87a43a2dd 100644 --- a/package/ios/RNSkia-iOS/SkiaManager.h +++ b/package/ios/RNSkia-iOS/SkiaManager.h @@ -12,6 +12,8 @@ - (void)invalidate; -- (instancetype)initWithBridge:(RCTBridge *)bridge jsInvoker:(std::shared_ptr)jsInvoker; +- (instancetype)initWithBridge:(RCTBridge *)bridge + jsInvoker:(std::shared_ptr) + jsInvoker; @end diff --git a/package/ios/RNSkia-iOS/SkiaManager.mm b/package/ios/RNSkia-iOS/SkiaManager.mm index 06938f2d0f..7d3cf594d5 100644 --- a/package/ios/RNSkia-iOS/SkiaManager.mm +++ b/package/ios/RNSkia-iOS/SkiaManager.mm @@ -24,7 +24,9 @@ - (void)invalidate { _skManager = nullptr; } -- (instancetype)initWithBridge:(RCTBridge *)bridge jsInvoker:(std::shared_ptr)jsInvoker { +- (instancetype)initWithBridge:(RCTBridge *)bridge + jsInvoker:(std::shared_ptr) + jsInvoker { self = [super init]; if (self) { RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge; @@ -36,7 +38,8 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge jsInvoker:(std::shared_ptr( jsRuntime, jsInvoker, - std::make_shared(jsRuntime, bridge, jsInvoker)); + std::make_shared(jsRuntime, bridge, + jsInvoker)); } } return self;