Skip to content

Commit d56096b

Browse files
committed
Add android polyfill error thrower
1 parent 271e5c6 commit d56096b

File tree

4 files changed

+25
-29
lines changed

4 files changed

+25
-29
lines changed

android/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ set (CMAKE_CXX_STANDARD 11)
55

66
add_library(rnmultithreading
77
SHARED
8-
../cpp/RNMultithreadingInstaller.cpp
8+
# ../cpp/RNMultithreadingInstaller.cpp
99
cpp-adapter.cpp
1010
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
11-
../../react-native-reanimated/android/src/main/cpp/AndroidErrorHandler.cpp
12-
../../react-native-reanimated/android/src/main/cpp/AndroidScheduler.cpp
11+
# ../../react-native-reanimated/android/src/main/cpp/AndroidErrorHandler.cpp
12+
# ../../react-native-reanimated/android/src/main/cpp/AndroidScheduler.cpp
1313
)
1414

1515
# Specifies a path to native header files.
@@ -18,9 +18,9 @@ include_directories(
1818
../../react-native/React
1919
../../react-native/React/Base
2020
../../react-native/ReactCommon/jsi
21-
../../react-native-reanimated/android/src/main/cpp/headers
22-
../../react-native-reanimated/Common/cpp/headers
23-
../../react-native-reanimated/Common/cpp/hidden_headers
21+
# ../../react-native-reanimated/android/src/main/cpp/headers
22+
# ../../react-native-reanimated/Common/cpp/headers
23+
# ../../react-native-reanimated/Common/cpp/hidden_headers
2424
)
2525

2626
find_library(

android/cpp-adapter.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
#include <jni.h>
22
#include <jsi/jsi.h>
3-
#include <jsi/JSIDynamic.h>
4-
#include "RNMultithreadingInstaller.h"
5-
#include "AndroidErrorHandler.h"
6-
#include "AndroidScheduler.h"
7-
#include <memory>
83

94
using namespace facebook;
105

116
extern "C"
127
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) {
189
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+
}));
2724
}

android/src/main/java/com/reactnativemultithreading/MultithreadingModule.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import com.facebook.react.bridge.ReactApplicationContext;
66
import com.facebook.react.bridge.ReactContextBaseJavaModule;
7-
import com.swmansion.reanimated.Scheduler;
7+
//import com.swmansion.reanimated.Scheduler;
88

99
public class MultithreadingModule extends ReactContextBaseJavaModule {
1010
static {
1111
System.loadLibrary("rnmultithreading");
1212
}
1313

14-
private native void nativeInstallMultithreading(long jsiPtr, Scheduler scheduler);
14+
private native void nativeInstallMultithreading(long jsiPtr);
1515

1616
public MultithreadingModule(ReactApplicationContext context) {
1717
super(context);
@@ -28,8 +28,7 @@ public void initialize() {
2828
super.initialize();
2929

3030
nativeInstallMultithreading(
31-
this.getReactApplicationContext().getJavaScriptContextHolder().get(),
32-
new Scheduler(getReactApplicationContext())
31+
this.getReactApplicationContext().getJavaScriptContextHolder().get()
3332
);
3433
}
3534
}

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ const styles = StyleSheet.create({
7878
},
7979
input: {
8080
width: '50%',
81-
height: 30,
8281
marginVertical: 10,
8382
borderWidth: StyleSheet.hairlineWidth,
8483
borderRadius: 5,
8584
borderColor: 'black',
8685
textAlign: 'center',
86+
fontSize: 14,
8787
},
8888
});

0 commit comments

Comments
 (0)