1111
1212#include < AndroidExtensions/Globals.h>
1313
14- #include < arcana/threading/task_schedulers.h>
15-
1614#include < android/log.h>
1715#include < android/native_window.h>
1816#include < android/native_window_jni.h>
2220#include < unistd.h>
2321
2422#include < jsi/jsi.h>
25-
26- #include " ../../../../shared/Shared.h"
23+ #include < ReactCommon/CallInvokerHolder.h>
2724
2825namespace Babylon
2926{
@@ -39,32 +36,15 @@ namespace Babylon
3936 {
4037 public:
4138 // This class must be constructed from the JavaScript thread
42- Native (facebook::jsi::Runtime* jsiRuntime, ANativeWindow* windowPtr)
39+ Native (facebook::jsi::Runtime* jsiRuntime, std::shared_ptr<facebook::react::CallInvoker> callInvoker, ANativeWindow* windowPtr)
4340 : m_env{ Napi::Attach<facebook::jsi::Runtime&>(*jsiRuntime) }
4441 {
45- struct DispatchData
46- {
47- using looper_scheduler_t = arcana::looper_scheduler<128 >;
48-
49- looper_scheduler_t scheduler;
50- Napi::FunctionReference flushedQueue;
51-
52- DispatchData (Napi::Env env)
53- : scheduler{ looper_scheduler_t::get_for_current_thread () }
54- , flushedQueue{ GetFlushedQueue (env) }
55- {
56- }
57- };
58-
5942 JsRuntime::DispatchFunctionT dispatchFunction =
60- [env = m_env, data = std::make_shared<DispatchData>(m_env) ](std::function<void (Napi::Env)> func)
43+ [env = m_env, callInvoker ](std::function<void (Napi::Env)> func)
6144 {
62- (data-> scheduler ) ([env, func = std::move (func), &data]()
45+ callInvoker-> invokeAsync ([env, func = std::move (func)]
6346 {
6447 func (env);
65- // NOTE: This doesn't work quite right on iOS, so we'll use a different work around until
66- // we have a better solution (see Shared.h and EngineHook.ts for more details).
67- // data->flushedQueue.Call({});
6848 });
6949 };
7050
@@ -153,11 +133,12 @@ extern "C" JNIEXPORT void JNICALL Java_com_reactlibrary_BabylonNativeInterop_res
153133 android::global::Resume ();
154134}
155135
156- extern " C" JNIEXPORT jlong JNICALL Java_com_reactlibrary_BabylonNativeInterop_create (JNIEnv* env, jclass obj, jlong jsiRuntimeRef, jobject surface)
136+ extern " C" JNIEXPORT jlong JNICALL Java_com_reactlibrary_BabylonNativeInterop_create (JNIEnv* env, jclass obj, jlong jsiRuntimeRef, jobject jsCallInvokerHolder, jobject surface)
157137{
158138 auto jsiRuntime = reinterpret_cast <facebook::jsi::Runtime*>(jsiRuntimeRef);
139+ auto callInvoker = facebook::jni::alias_ref<facebook::react::CallInvokerHolder::javaobject> {reinterpret_cast <facebook::react::CallInvokerHolder::javaobject>(jsCallInvokerHolder)}->cthis ()->getCallInvoker ();
159140 ANativeWindow* windowPtr = ANativeWindow_fromSurface (env, surface);
160- auto native = new Babylon::Native (jsiRuntime, windowPtr);
141+ auto native = new Babylon::Native (jsiRuntime, callInvoker, windowPtr);
161142 return reinterpret_cast <intptr_t >(native);
162143}
163144
0 commit comments