Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix bridgeless support on iOS #2223

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading