Skip to content

Commit

Permalink
Fix bridgeless support on iOS (#2223)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: William Candillon <wcandillon@gmail.com>
  • Loading branch information
Kudo and wcandillon authored Feb 19, 2024
1 parent f70066b commit 547a861
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
7 changes: 4 additions & 3 deletions package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h>
#import <ReactCommon/RCTTurboModule.h>

#include <functional>
#include <memory>
Expand Down Expand Up @@ -30,8 +29,10 @@ 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<facebook::react::CallInvoker> jsCallInvoker)
: RNSkPlatformContext(runtime, jsCallInvoker,
[[UIScreen mainScreen] scale]) {

// We need to make sure we invalidate when modules are freed
Expand Down
4 changes: 3 additions & 1 deletion package/ios/RNSkia-iOS/SkiaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- (void)invalidate;

- (instancetype)initWithBridge:(RCTBridge *)bridge;
- (instancetype)initWithBridge:(RCTBridge *)bridge
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)
jsInvoker;

@end
11 changes: 6 additions & 5 deletions package/ios/RNSkia-iOS/SkiaManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#import <React/RCTBridge.h>
#import <React/RCTUIManager.h>

#import <ReactCommon/RCTTurboModule.h>

#import "RNSkiOSPlatformContext.h"

@implementation SkiaManager {
Expand All @@ -26,7 +24,9 @@ - (void)invalidate {
_skManager = nullptr;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge {
- (instancetype)initWithBridge:(RCTBridge *)bridge
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)
jsInvoker {
self = [super init];
if (self) {
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
Expand All @@ -37,8 +37,9 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge {

// Create the RNSkiaManager (cross platform)
_skManager = std::make_shared<RNSkia::RNSkManager>(
jsRuntime, bridge.jsCallInvoker,
std::make_shared<RNSkia::RNSkiOSPlatformContext>(jsRuntime, bridge));
jsRuntime, jsInvoker,
std::make_shared<RNSkia::RNSkiOSPlatformContext>(jsRuntime, bridge,
jsInvoker));
}
}
return self;
Expand Down
8 changes: 7 additions & 1 deletion package/ios/RNSkiaModule.mm
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

#import "RNSkiaModule.h"
#import <React/RCTBridge+Private.h>
#import <ReactCommon/RCTTurboModule.h>

@implementation RNSkiaModule {
SkiaManager *skiaManager;
std::shared_ptr<facebook::react::CallInvoker> jsInvoker;
}

RCT_EXPORT_MODULE()
Expand Down Expand Up @@ -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<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params {
jsInvoker = params.jsInvoker;
return std::make_shared<facebook::react::NativeSkiaModuleSpecJSI>(params);
}
#endif
Expand Down

0 comments on commit 547a861

Please # to comment.