Skip to content

Commit

Permalink
Merge pull request #3 from SamuelScheit/ios-support
Browse files Browse the repository at this point in the history
  • Loading branch information
laptou authored Oct 11, 2024
2 parents c90f7d4 + 69a0b18 commit 72afac1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
7 changes: 7 additions & 0 deletions example/example-jsi-module/src/ios.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[no_mangle]
pub extern "C" fn ExampleJsiModule_init(
rt: *mut jsi::sys::Runtime,
call_invoker: cxx::SharedPtr<jsi::sys::CallInvoker>,
) {
crate::init(rt, call_invoker);
}
3 changes: 3 additions & 0 deletions example/example-jsi-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use jsi::{
#[cfg(target_os = "android")]
mod android;

#[cfg(target_os = "ios")]
mod ios;

pub fn init(rt: *mut jsi::sys::Runtime, call_invoker: cxx::SharedPtr<jsi::sys::CallInvoker>) {
let (mut rt, _) = jsi::init(rt, call_invoker);

Expand Down
11 changes: 11 additions & 0 deletions example/ios/example/ExampleJsiModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#ifndef ExampleJsiModule_h
#define ExampleJsiModule_h

#include <memory>

extern "C" {
void ExampleJsiModule_init(void* rt, std::shared_ptr<void> ctx);
}

#endif
11 changes: 11 additions & 0 deletions example/ios/example/RCTExampleJsiModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef RCTExampleJsiModule_h
#define RCTExampleJsiModule_h

#include "ExampleJsiModule.h"

#import <React/RCTBridgeModule.h>
@interface RCTExampleJsiModule : NSObject <RCTBridgeModule>
@end


#endif /* RCTExampleJsiModule_h */
48 changes: 48 additions & 0 deletions example/ios/example/RTCExampleJsiModule.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#import <Foundation/Foundation.h>
#import "RCTExampleJsiModule.h"

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

@implementation RCTExampleJsiModule

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE(ExampleJsiModule)

- (void)invalidate {
_bridge = nil;
}

- (void)setBridge:(RCTBridge *)bridge {
_bridge = bridge;
}

+ (BOOL)requiresMainQueueSetup {
return YES;
}


void installApi(std::shared_ptr<facebook::react::CallInvoker> callInvoker,
facebook::jsi::Runtime *runtime) {

ExampleJsiModule_init((void*)runtime, (std::shared_ptr<void>) callInvoker);
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)_bridge;
if (cxxBridge.runtime != nullptr) {
auto callInvoker = cxxBridge.jsCallInvoker;
facebook::jsi::Runtime *jsRuntime = (facebook::jsi::Runtime *)cxxBridge.runtime;

installApi(callInvoker, jsRuntime);
return @true;
}
return @false;
}


@end

0 comments on commit 72afac1

Please sign in to comment.