|
1 | 1 | #include <jni.h>
|
2 | 2 | #include <jsi/jsi.h>
|
3 |
| -#include <jsi/JSIDynamic.h> |
4 |
| -#include "RNMultithreadingInstaller.h" |
5 |
| -#include "AndroidErrorHandler.h" |
6 |
| -#include "AndroidScheduler.h" |
7 |
| -#include <memory> |
8 | 3 |
|
9 | 4 | using namespace facebook;
|
10 | 5 |
|
11 | 6 | extern "C"
|
12 | 7 | JNIEXPORT void JNICALL
|
13 |
| -Java_com_reactnativemultithreading_MultithreadingModule_nativeInstallMultithreading(JNIEnv *env, |
14 |
| - jobject clazz, |
15 |
| - jlong jsiPtr, |
16 |
| - jni::alias_ref<facebook::react::CallInvokerHolder::javaobject> jsCallInvokerHolder, |
17 |
| - jni::alias_ref<AndroidScheduler::javaobject> androidScheduler) { |
| 8 | +Java_com_reactnativemultithreading_MultithreadingModule_nativeInstallMultithreading(JNIEnv *env, jobject clazz, jlong jsiPtr) { |
18 | 9 | auto runtime = reinterpret_cast<jsi::Runtime*>(jsiPtr);
|
19 |
| - return mrousavy::multithreading::install(*runtime, []() { |
20 |
| - auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); |
21 |
| - auto scheduler = androidScheduler->cthis()->getScheduler(); |
22 |
| - scheduler->setJSCallInvoker(jsCallInvoker); |
23 |
| - return scheduler; |
24 |
| - }, [](std::shared_ptr<reanimated::AndroidScheduler> scheduler) { |
25 |
| - return std::make_shared<reanimated::AndroidErrorHandler>(scheduler); |
26 |
| - }); |
| 10 | + |
| 11 | + // TODO: Implement multithreading for Android. |
| 12 | + // The only problem I have with this is that I cannot really import/include the Reanimated library since that is a prebuilt .aar. |
| 13 | + // That means, I cannot import it's headers, I cannot link it, and I cannot create instances of ShareableValue, AndroidErrorHandler, AndroidScheduler, ... |
| 14 | + runtime->global().setProperty(*runtime, |
| 15 | + "spawnThread", |
| 16 | + jsi::Function::createFromHostFunction(*runtime, |
| 17 | + jsi::PropNameID::forAscii(*runtime, "spawnThread"), |
| 18 | + 1, |
| 19 | + [](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { |
| 20 | + auto promise = runtime.global().getProperty(runtime, "Promise").asObject(runtime); |
| 21 | + auto rejecter = promise.getProperty(runtime, "reject"); |
| 22 | + return rejecter.asObject(runtime).asFunction(runtime).call(runtime, jsi::JSError(runtime, "Multithreading is not yet supported on Android.").value()); |
| 23 | + })); |
27 | 24 | }
|
0 commit comments