-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
#include <fbjni/fbjni.h> | ||
#include <jni.h> | ||
#include "FilamentInstaller.h" | ||
#include "JFilamentProxy.h" | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) { | ||
return facebook::jni::initialize(vm, [] { margelo::FilamentInstaller::registerNatives(); }); | ||
return facebook::jni::initialize(vm, [] { | ||
margelo::FilamentInstaller::registerNatives(); | ||
margelo::JFilamentProxy::registerNatives(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <jni.h> | ||
#include <fbjni/fbjni.h> | ||
#include <jsi/jsi.h> | ||
#include "FilamentInstaller.h" | ||
#include "AndroidFilamentProxy.h" | ||
|
||
namespace margelo { | ||
|
||
void FilamentInstaller::install(jni::alias_ref<jni::JClass> clazz, | ||
jni::alias_ref<JFilamentProxy::javaobject> proxy) { | ||
jsi::Runtime& runtime = proxy->cthis()->getRuntime(); | ||
std::shared_ptr<AndroidFilamentProxy> filamentProxy = std::make_shared<AndroidFilamentProxy>(proxy); | ||
runtime.global().setProperty(runtime, "__filamentProxy", jsi::Object::createFromHostObject(runtime, filamentProxy)); | ||
} | ||
|
||
void FilamentInstaller::registerNatives() { | ||
javaClassStatic()->registerNatives({makeNativeMethod("install", FilamentInstaller::install)}); | ||
} | ||
|
||
} // namespace margelo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
package/android/src/main/java/com/margelo/filament/FilamentInstaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.margelo.filament; | ||
|
||
/** @noinspection JavaJniMissingFunction*/ | ||
public class FilamentInstaller { | ||
public static native void install(FilamentProxy proxy); | ||
} |
37 changes: 37 additions & 0 deletions
37
package/android/src/main/java/com/margelo/filament/FilamentProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
package com.margelo.filament; | ||
|
||
import androidx.annotation.Keep; | ||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.jni.HybridData; | ||
import com.facebook.proguard.annotations.DoNotStrip; | ||
import com.facebook.react.bridge.JavaScriptContextHolder; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; | ||
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; | ||
|
||
/** @noinspection JavaJniMissingFunction*/ | ||
class FilamentProxy { | ||
/** @noinspection unused, FieldCanBeLocal */ | ||
@DoNotStrip | ||
@Keep | ||
private final HybridData hybridData; | ||
|
||
FilamentProxy(@NonNull ReactApplicationContext context) { | ||
JavaScriptContextHolder jsRuntimeHolder = context.getJavaScriptContextHolder(); | ||
if (jsRuntimeHolder == null) { | ||
throw new RuntimeException("Failed to initialize react-native-filament: JSI Runtime Holder is null!"); | ||
} | ||
Long runtimePointer = jsRuntimeHolder.get(); | ||
CallInvokerHolder callInvokerHolder = context.getCatalystInstance().getJSCallInvokerHolder(); | ||
if (!(callInvokerHolder instanceof CallInvokerHolderImpl)) { | ||
throw new RuntimeException("Failed to initialize react-native-filament: JS Call Invoker is null!"); | ||
} | ||
hybridData = initHybrid(runtimePointer, (CallInvokerHolderImpl) callInvokerHolder); | ||
} | ||
|
||
/** @noinspection unused*/ | ||
@DoNotStrip | ||
@Keep | ||
int loadModel(String path) { | ||
// TODO(hanno): Implement Java part here | ||
return 13; | ||
} | ||
|
||
private native HybridData initHybrid(Long jsRuntimePointer, CallInvokerHolderImpl callInvokerHolder); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters