Skip to content

Commit

Permalink
Implement iOS Part
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 20, 2024
1 parent 220ede5 commit b3ab95c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package/android/src/main/cpp/AndroidFilamentProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AndroidFilamentProxy : public FilamentProxy {

private:
// TODO(hanno): implement
int loadModel(const std::string& path);
int loadModel(const std::string& path) override;

private:
jni::global_ref<JFilamentProxy::javaobject> _proxy;
Expand Down
17 changes: 16 additions & 1 deletion package/ios/AppleFilamentProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@
//

#include "FilamentProxy.h"
#include <jsi/jsi.h>
#include <ReactCommon/CallInvoker.h>

namespace margelo {

class AppleFilamentProxy : public FilamentProxy {
public:
explicit AppleFilamentProxy(jsi::Runtime* runtime, std::shared_ptr<react::CallInvoker> callInvoker);
~AppleFilamentProxy();
}

public:
int loadModel(const std::string &path) override;

private:
jsi::Runtime* _runtime;
std::shared_ptr<react::CallInvoker> _callInvoker;
};

} // namespace margelo
25 changes: 25 additions & 0 deletions package/ios/AppleFilamentProxy.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// AppleFilamentProxy.mm
// react-native-filament
//
// Created by Marc Rousavy on 20.02.24.
//

#import <Foundation/Foundation.h>
#import "AppleFilamentProxy.h"

namespace margelo {

AppleFilamentProxy::AppleFilamentProxy(jsi::Runtime* runtime, std::shared_ptr<react::CallInvoker> callInvoker):
_runtime(runtime), _callInvoker(callInvoker) { }

AppleFilamentProxy::~AppleFilamentProxy() {
// TODO(hanno): cleanup here?
}

int AppleFilamentProxy::loadModel(const std::string &path) {
// TODO(hanno): Implement model loading here
return 13;
}

} // namespace margelo
15 changes: 15 additions & 0 deletions package/ios/FilamentInstaller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// IOSFilamentInstaller.h
// react-native-filament
//
// Created by Marc Rousavy on 20.02.24.
//

#import <Foundation/Foundation.h>
#import <React/RCTBridge.h>

@interface FilamentInstaller : NSObject

+ (BOOL)installToBridge:(RCTBridge*)bridge;

@end
47 changes: 47 additions & 0 deletions package/ios/FilamentInstaller.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// FilamentInstaller.m
// react-native-filament
//
// Created by Marc Rousavy on 20.02.24.
//

#import <Foundation/Foundation.h>
#import "FilamentInstaller.h"
#import "AppleFilamentProxy.h"
#import <ReactCommon/CallInvoker.h>

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

using namespace facebook;

// This is defined in RCTCxxBridge.mm, and we are technically using a private API here.
@interface RCTCxxBridge (CallInvoker)
- (std::shared_ptr<react::CallInvoker>)jsCallInvoker;
@end

@implementation FilamentInstaller

+ (BOOL)installToBridge:(RCTBridge *)bridge {
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)[RCTBridge currentBridge];
if (!cxxBridge.runtime) {
return NO;
}

jsi::Runtime* runtime = (jsi::Runtime*)cxxBridge.runtime;
if (!runtime) {
return NO;
}
std::shared_ptr<react::CallInvoker> callInvoker = cxxBridge.jsCallInvoker;
if (!callInvoker) {
return NO;
}

// global.__filamentProxy
auto filamentProxy = std::make_shared<margelo::AppleFilamentProxy>(runtime, callInvoker);
runtime->global().setProperty(*runtime, "__filamentProxy", jsi::Object::createFromHostObject(*runtime, filamentProxy));

return YES;
}

@end

0 comments on commit b3ab95c

Please sign in to comment.