react-native-nitro-modules 0.33.1 → 0.33.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +1 -0
- package/android/build.gradle +1 -1
- package/android/src/main/cpp/JNIOnLoad.cpp +2 -0
- package/android/src/main/cpp/platform/ThreadUtils.cpp +17 -17
- package/android/src/main/cpp/threading/UIThreadDispatcher.cpp +21 -0
- package/android/src/main/cpp/threading/UIThreadDispatcher.hpp +14 -0
- package/android/src/main/cpp/utils/JNativeRunnable.hpp +32 -0
- package/android/src/main/cpp/utils/JThreadUtils.hpp +39 -0
- package/android/src/main/java/com/margelo/nitro/utils/NativeRunnable.kt +18 -0
- package/android/src/main/java/com/margelo/nitro/utils/ThreadUtils.kt +43 -0
- package/cpp/core/BoxedHybridObject.cpp +4 -5
- package/cpp/core/HybridObject.cpp +4 -2
- package/cpp/jsi/JSIConverter+AnyMap.hpp +1 -1
- package/cpp/jsi/JSIConverter+ArrayBuffer.hpp +5 -2
- package/cpp/jsi/JSIConverter+Function.hpp +6 -2
- package/cpp/platform/ThreadUtils.hpp +13 -0
- package/cpp/prototype/HybridObjectPrototype.cpp +5 -2
- package/cpp/threading/Dispatcher.cpp +6 -0
- package/cpp/utils/CommonGlobals.cpp +5 -2
- package/cpp/utils/NitroDefines.hpp +1 -1
- package/cpp/utils/PropNameIDCache.hpp +12 -0
- package/cpp/views/CachedProp.hpp +5 -2
- package/ios/core/AnyMap.swift +0 -2
- package/ios/core/HybridObject.swift +0 -2
- package/ios/core/Null.swift +0 -2
- package/ios/core/Promise.swift +0 -2
- package/ios/core/RuntimeError.swift +0 -2
- package/ios/platform/ThreadUtils.cpp +9 -0
- package/ios/threading/UIThreadDispatcher.cpp +19 -0
- package/ios/threading/UIThreadDispatcher.hpp +19 -0
- package/ios/utils/MemoryHelper.swift +0 -2
- package/ios/utils/SwiftClosure.swift +0 -2
- package/ios/views/HybridView.swift +0 -1
- package/ios/views/RecyclableView.swift +0 -2
- package/lib/commonjs/index.js +2 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/views/getHostComponent.js +7 -2
- package/lib/commonjs/views/getHostComponent.js.map +1 -1
- package/lib/commonjs/worklets/installWorkletsSupport.js +38 -0
- package/lib/commonjs/worklets/installWorkletsSupport.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/views/getHostComponent.js +6 -2
- package/lib/module/views/getHostComponent.js.map +1 -1
- package/lib/module/worklets/installWorkletsSupport.js +34 -0
- package/lib/module/worklets/installWorkletsSupport.js.map +1 -0
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/views/getHostComponent.d.ts.map +1 -1
- package/lib/typescript/worklets/installWorkletsSupport.d.ts +2 -0
- package/lib/typescript/worklets/installWorkletsSupport.d.ts.map +1 -0
- package/package.json +5 -4
- package/src/index.ts +4 -0
- package/src/views/getHostComponent.ts +10 -2
- package/src/worklets/installWorkletsSupport.ts +30 -0
package/android/CMakeLists.txt
CHANGED
package/android/build.gradle
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include "JAnyValue.hpp"
|
|
5
5
|
#include "JArrayBuffer.hpp"
|
|
6
6
|
#include "JHardwareBufferUtils.hpp"
|
|
7
|
+
#include "JNativeRunnable.hpp"
|
|
7
8
|
#include "JNitroModules.hpp"
|
|
8
9
|
#include "JPromise.hpp"
|
|
9
10
|
#include <fbjni/fbjni.h>
|
|
@@ -19,6 +20,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
|
19
20
|
JAnyValue::registerNatives();
|
|
20
21
|
JHardwareBufferUtils::registerNatives();
|
|
21
22
|
JPromise::registerNatives();
|
|
23
|
+
JNativeRunnable::registerNatives();
|
|
22
24
|
|
|
23
25
|
// 2. Initialize the React Native TurboModule C++ part
|
|
24
26
|
JNitroModules::registerNatives();
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
#include "ThreadUtils.hpp"
|
|
9
|
+
#include "JThreadUtils.hpp"
|
|
10
|
+
#include "UIThreadDispatcher.hpp"
|
|
9
11
|
#include <pthread.h>
|
|
10
12
|
#include <sstream>
|
|
11
13
|
#include <string>
|
|
@@ -14,27 +16,25 @@
|
|
|
14
16
|
|
|
15
17
|
namespace margelo::nitro {
|
|
16
18
|
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
// Implementation for the C++ shared `ThreadUtils` class
|
|
17
22
|
std::string ThreadUtils::getThreadName() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
pthread_t thisThread = pthread_self();
|
|
21
|
-
char threadName[16]; // Thread name length limit in Android is 16 characters
|
|
22
|
-
|
|
23
|
-
int result = pthread_getname_np(thisThread, threadName, sizeof(threadName));
|
|
24
|
-
if (result == 0) {
|
|
25
|
-
return std::string(threadName);
|
|
26
|
-
}
|
|
27
|
-
#endif
|
|
28
|
-
|
|
29
|
-
// Fall back to this_thread ID
|
|
30
|
-
std::stringstream stream;
|
|
31
|
-
stream << std::this_thread::get_id();
|
|
32
|
-
std::string threadId = stream.str();
|
|
33
|
-
return "Thread #" + threadId;
|
|
23
|
+
auto name = JThreadUtils::getCurrentThreadName();
|
|
24
|
+
return name->toStdString();
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
void ThreadUtils::setThreadName(const std::string& name) {
|
|
37
|
-
|
|
28
|
+
auto jName = jni::make_jstring(name);
|
|
29
|
+
JThreadUtils::setCurrentThreadName(jName);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
bool ThreadUtils::isUIThread() {
|
|
33
|
+
return JThreadUtils::isOnUIThread();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
std::shared_ptr<Dispatcher> ThreadUtils::createUIThreadDispatcher() {
|
|
37
|
+
return std::make_shared<UIThreadDispatcher>();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
} // namespace margelo::nitro
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Marc Rousavy on 29.01.26.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#include "UIThreadDispatcher.hpp"
|
|
6
|
+
#include "JNativeRunnable.hpp"
|
|
7
|
+
#include "JThreadUtils.hpp"
|
|
8
|
+
#include <fbjni/fbjni.h>
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro {
|
|
11
|
+
using namespace facebook;
|
|
12
|
+
|
|
13
|
+
void UIThreadDispatcher::runAsync(std::function<void()>&& function) {
|
|
14
|
+
auto runnable = JNativeRunnable::newObjectCxxArgs(std::move(function));
|
|
15
|
+
JThreadUtils::runOnUIThread(runnable);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void UIThreadDispatcher::runSync(std::function<void()>&&) {
|
|
19
|
+
throw std::runtime_error("UIThreadDispatcher::runSync() is not implemented!");
|
|
20
|
+
}
|
|
21
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "Dispatcher.hpp"
|
|
5
|
+
|
|
6
|
+
namespace margelo::nitro {
|
|
7
|
+
|
|
8
|
+
class UIThreadDispatcher : public Dispatcher {
|
|
9
|
+
public:
|
|
10
|
+
void runSync(std::function<void()>&& function) override;
|
|
11
|
+
void runAsync(std::function<void()>&& function) override;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Marc Rousavy on 29.01.26.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <fbjni/fbjni.h>
|
|
8
|
+
|
|
9
|
+
namespace margelo::nitro {
|
|
10
|
+
|
|
11
|
+
using namespace facebook;
|
|
12
|
+
|
|
13
|
+
class JNativeRunnable : public jni::HybridClass<JNativeRunnable> {
|
|
14
|
+
public:
|
|
15
|
+
explicit JNativeRunnable(std::function<void()>&& func) : _func(std::move(func)) {}
|
|
16
|
+
|
|
17
|
+
void run() {
|
|
18
|
+
_func();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public:
|
|
22
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/NativeRunnable;";
|
|
23
|
+
static void registerNatives() {
|
|
24
|
+
registerHybrid({makeNativeMethod("run", JNativeRunnable::run)});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private:
|
|
28
|
+
friend HybridBase;
|
|
29
|
+
std::function<void()> _func;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JThreadUtils.hpp
|
|
3
|
+
// react-native-nitro
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 14.07.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#include "JNativeRunnable.hpp"
|
|
9
|
+
#include <fbjni/fbjni.h>
|
|
10
|
+
#include <string>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro {
|
|
13
|
+
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
// Bridged to Java
|
|
17
|
+
class JThreadUtils : public jni::JavaClass<JThreadUtils> {
|
|
18
|
+
public:
|
|
19
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/utils/ThreadUtils;";
|
|
20
|
+
|
|
21
|
+
static jni::local_ref<jni::JString> getCurrentThreadName() {
|
|
22
|
+
static auto method = javaClassStatic()->getStaticMethod<jni::local_ref<jni::JString>()>("getCurrentThreadName");
|
|
23
|
+
return method(javaClassStatic());
|
|
24
|
+
}
|
|
25
|
+
static void setCurrentThreadName(jni::alias_ref<jni::JString> name) {
|
|
26
|
+
static auto method = javaClassStatic()->getStaticMethod<void(jni::alias_ref<jni::JString>)>("setCurrentThreadName");
|
|
27
|
+
method(javaClassStatic(), name);
|
|
28
|
+
}
|
|
29
|
+
static jboolean isOnUIThread() {
|
|
30
|
+
static auto method = javaClassStatic()->getStaticMethod<jboolean()>("isOnUIThread");
|
|
31
|
+
return method(javaClassStatic());
|
|
32
|
+
}
|
|
33
|
+
static void runOnUIThread(jni::alias_ref<JNativeRunnable::javaobject> runnable) {
|
|
34
|
+
static auto method = javaClassStatic()->getStaticMethod<void(jni::alias_ref<JNativeRunnable::javaobject>)>("runOnUIThread");
|
|
35
|
+
method(javaClassStatic(), runnable);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.margelo.nitro.utils
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Keep
|
|
4
|
+
import com.facebook.jni.HybridData
|
|
5
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
6
|
+
|
|
7
|
+
@Suppress("unused", "KotlinJniMissingFunction")
|
|
8
|
+
@DoNotStrip
|
|
9
|
+
@Keep
|
|
10
|
+
class NativeRunnable : Runnable {
|
|
11
|
+
private var mHybridData: HybridData
|
|
12
|
+
|
|
13
|
+
private constructor(hybridData: HybridData) {
|
|
14
|
+
mHybridData = hybridData
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
external override fun run()
|
|
18
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package com.margelo.nitro.utils
|
|
2
|
+
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import androidx.annotation.Keep
|
|
6
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
7
|
+
|
|
8
|
+
@Suppress("unused")
|
|
9
|
+
@Keep
|
|
10
|
+
@DoNotStrip
|
|
11
|
+
class ThreadUtils {
|
|
12
|
+
companion object {
|
|
13
|
+
private val handler = Handler(Looper.getMainLooper())
|
|
14
|
+
|
|
15
|
+
@JvmStatic
|
|
16
|
+
@Keep
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
fun getCurrentThreadName(): String {
|
|
19
|
+
return Thread.currentThread().name
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@JvmStatic
|
|
23
|
+
@Keep
|
|
24
|
+
@DoNotStrip
|
|
25
|
+
fun setCurrentThreadName(name: String) {
|
|
26
|
+
Thread.currentThread().name = name
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@JvmStatic
|
|
30
|
+
@Keep
|
|
31
|
+
@DoNotStrip
|
|
32
|
+
fun isOnUIThread(): Boolean {
|
|
33
|
+
return Looper.myLooper() == Looper.getMainLooper()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@JvmStatic
|
|
37
|
+
@Keep
|
|
38
|
+
@DoNotStrip
|
|
39
|
+
fun runOnUIThread(runnable: Runnable) {
|
|
40
|
+
handler.post(runnable)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -10,14 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
namespace margelo::nitro {
|
|
12
12
|
|
|
13
|
-
std::vector<jsi::PropNameID> BoxedHybridObject::getPropertyNames(
|
|
14
|
-
return
|
|
13
|
+
std::vector<jsi::PropNameID> BoxedHybridObject::getPropertyNames(jsi::Runtime& runtime) {
|
|
14
|
+
return PropNameIDCache::names(runtime, "unbox");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
jsi::Value BoxedHybridObject::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (name == "unbox") {
|
|
18
|
+
if (jsi::PropNameID::compare(runtime, propName, PropNameIDCache::get(runtime, "unbox"))) {
|
|
19
|
+
// .unbox()
|
|
21
20
|
return jsi::Function::createFromHostFunction(
|
|
22
21
|
runtime, PropNameIDCache::get(runtime, "unbox"), 0,
|
|
23
22
|
[hybridObject = _hybridObject](jsi::Runtime& runtime, const jsi::Value&, const jsi::Value*, size_t) -> jsi::Value {
|
|
@@ -97,8 +97,10 @@ jsi::Value HybridObject::toObject(jsi::Runtime& runtime) {
|
|
|
97
97
|
#endif
|
|
98
98
|
|
|
99
99
|
// 7. Throw a jsi::WeakObject pointing to our object into cache so subsequent calls can use it from cache
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
{
|
|
101
|
+
JSICacheReference cache = JSICache::getOrCreateCache(runtime);
|
|
102
|
+
_objectCache[&runtime] = cache.makeShared(jsi::WeakObject(runtime, object));
|
|
103
|
+
}
|
|
102
104
|
|
|
103
105
|
// 8. Return it!
|
|
104
106
|
return object;
|
|
@@ -47,7 +47,7 @@ struct JSIConverter<std::shared_ptr<AnyMap>> final {
|
|
|
47
47
|
jsi::Object object = arg.asObject(runtime);
|
|
48
48
|
jsi::Array propNames = object.getPropertyNames(runtime);
|
|
49
49
|
size_t size = propNames.size(runtime);
|
|
50
|
-
std::shared_ptr<AnyMap> map = AnyMap::make();
|
|
50
|
+
std::shared_ptr<AnyMap> map = AnyMap::make(size);
|
|
51
51
|
for (size_t i = 0; i < size; i++) {
|
|
52
52
|
std::string jsKey = propNames.getValueAtIndex(runtime, i).getString(runtime).utf8(runtime);
|
|
53
53
|
jsi::Value jsValue = object.getProperty(runtime, PropNameIDCache::get(runtime, jsKey));
|
|
@@ -62,8 +62,11 @@ struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_v<T, jsi::MutableBuffer
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
BorrowingReference<jsi::ArrayBuffer> borrowingArrayBuffer;
|
|
66
|
+
{
|
|
67
|
+
JSICacheReference cache = JSICache::getOrCreateCache(runtime);
|
|
68
|
+
borrowingArrayBuffer = cache.makeShared(object.getArrayBuffer(runtime));
|
|
69
|
+
}
|
|
67
70
|
|
|
68
71
|
return std::make_shared<JSArrayBuffer>(runtime, borrowingArrayBuffer);
|
|
69
72
|
}
|
|
@@ -33,9 +33,13 @@ struct JSIConverter<std::function<R(Args...)>> final {
|
|
|
33
33
|
|
|
34
34
|
static inline std::function<R(Args...)> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
35
35
|
// Make function global - it'll be managed by the Runtime's memory, and we only have a weak_ref to it.
|
|
36
|
-
auto cache = JSICache::getOrCreateCache(runtime);
|
|
37
36
|
jsi::Function function = arg.asObject(runtime).asFunction(runtime);
|
|
38
|
-
BorrowingReference<jsi::Function> sharedFunction
|
|
37
|
+
BorrowingReference<jsi::Function> sharedFunction;
|
|
38
|
+
{
|
|
39
|
+
// JSICache RAII should live as short as possible
|
|
40
|
+
JSICacheReference cache = JSICache::getOrCreateCache(runtime);
|
|
41
|
+
sharedFunction = cache.makeShared(std::move(function));
|
|
42
|
+
}
|
|
39
43
|
SyncJSCallback<ActualR(Args...)> callback(runtime, std::move(sharedFunction));
|
|
40
44
|
|
|
41
45
|
if constexpr (isAsync) {
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
|
+
#include "Dispatcher.hpp"
|
|
11
|
+
#include <memory>
|
|
10
12
|
#include <string>
|
|
11
13
|
|
|
12
14
|
namespace margelo::nitro {
|
|
@@ -26,6 +28,17 @@ public:
|
|
|
26
28
|
* This is implemented differently on iOS and Android.
|
|
27
29
|
*/
|
|
28
30
|
static void setThreadName(const std::string& name);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets whether the caller is currently running
|
|
34
|
+
* on the Main/UI Thread.
|
|
35
|
+
*/
|
|
36
|
+
static bool isUIThread();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a `Dispatcher` for the Main/UI Thread.
|
|
40
|
+
*/
|
|
41
|
+
static std::shared_ptr<Dispatcher> createUIThreadDispatcher();
|
|
29
42
|
};
|
|
30
43
|
|
|
31
44
|
} // namespace margelo::nitro
|
|
@@ -94,8 +94,11 @@ jsi::Value HybridObjectPrototype::createPrototype(jsi::Runtime& runtime, const s
|
|
|
94
94
|
#endif
|
|
95
95
|
|
|
96
96
|
// 8. Throw it into our cache so the next lookup can be cached and therefore faster
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
BorrowingReference<jsi::Object> sharedObject;
|
|
98
|
+
{
|
|
99
|
+
JSICacheReference jsiCache = JSICache::getOrCreateCache(runtime);
|
|
100
|
+
sharedObject = jsiCache.makeShared(std::move(object));
|
|
101
|
+
}
|
|
99
102
|
const NativeInstanceId& instanceId = prototype->getNativeInstanceId();
|
|
100
103
|
prototypeCache[instanceId] = sharedObject;
|
|
101
104
|
|
|
@@ -45,6 +45,12 @@ std::shared_ptr<Dispatcher> Dispatcher::getRuntimeGlobalDispatcher(jsi::Runtime&
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// If it's the main/UI Thread, we can inject the Dispatcher now
|
|
49
|
+
if (ThreadUtils::isUIThread()) {
|
|
50
|
+
auto uiDispatcher = ThreadUtils::createUIThreadDispatcher();
|
|
51
|
+
Dispatcher::installRuntimeGlobalDispatcher(runtime, uiDispatcher);
|
|
52
|
+
}
|
|
53
|
+
|
|
48
54
|
Logger::log(LogLevel::Warning, TAG, "Unknown Runtime (%s), looking for Dispatcher through JSI global lookup...",
|
|
49
55
|
getRuntimeId(runtime).c_str());
|
|
50
56
|
// 1. Get global.__nitroDispatcher
|
|
@@ -204,8 +204,11 @@ const jsi::Function& CommonGlobals::getGlobalFunction(jsi::Runtime& runtime, con
|
|
|
204
204
|
jsi::Function function = getFunction(runtime);
|
|
205
205
|
|
|
206
206
|
// Let's throw it in cache!
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
BorrowingReference<jsi::Function> sharedFunction;
|
|
208
|
+
{
|
|
209
|
+
JSICacheReference jsiCache = JSICache::getOrCreateCache(runtime);
|
|
210
|
+
sharedFunction = jsiCache.makeShared(std::move(function));
|
|
211
|
+
}
|
|
209
212
|
functionCache[stringKey] = sharedFunction;
|
|
210
213
|
|
|
211
214
|
// And now return:
|
|
@@ -37,6 +37,18 @@ public:
|
|
|
37
37
|
*/
|
|
38
38
|
static const jsi::PropNameID& get(jsi::Runtime& runtime, const std::string& value);
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Get a list of `jsi::PropNameID`s for the given strings.
|
|
42
|
+
* Useful for `jsi::HostObject::getPropertyNames(...)`.
|
|
43
|
+
*/
|
|
44
|
+
static std::vector<jsi::PropNameID> names(jsi::Runtime& runtime, const std::string& first, auto&&... rest) {
|
|
45
|
+
std::vector<jsi::PropNameID> out;
|
|
46
|
+
out.reserve(1 + sizeof...(rest));
|
|
47
|
+
out.emplace_back(runtime, PropNameIDCache::get(runtime, first));
|
|
48
|
+
(out.emplace_back(runtime, PropNameIDCache::get(runtime, std::forward<decltype(rest)>(rest))), ...);
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
private:
|
|
41
53
|
using CacheMap = std::unordered_map<std::string, BorrowingReference<jsi::PropNameID>>;
|
|
42
54
|
static std::unordered_map<jsi::Runtime*, CacheMap> _cache;
|
package/cpp/views/CachedProp.hpp
CHANGED
|
@@ -35,8 +35,11 @@ public:
|
|
|
35
35
|
return oldProp;
|
|
36
36
|
}
|
|
37
37
|
T converted = JSIConverter<T>::fromJSI(runtime, value);
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
BorrowingReference<jsi::Value> cached;
|
|
39
|
+
{
|
|
40
|
+
JSICacheReference cache = JSICache::getOrCreateCache(runtime);
|
|
41
|
+
cached = cache.makeShared(jsi::Value(runtime, value));
|
|
42
|
+
}
|
|
40
43
|
return CachedProp<T>(std::move(converted), std::move(cached), /* isDirty */ true);
|
|
41
44
|
}
|
|
42
45
|
};
|
package/ios/core/AnyMap.swift
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
// Created by Marc Rousavy on 20.08.24.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
|
-
|
|
10
8
|
/// Represents any value representable by the `AnyMap`.
|
|
11
9
|
/// Note: Arrays are currently not implemented due to a Swift compiler bug https://github.com/swiftlang/swift/issues/75994
|
|
12
10
|
public indirect enum AnyValue {
|
package/ios/core/Null.swift
CHANGED
package/ios/core/Promise.swift
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
#include "ThreadUtils.hpp"
|
|
9
|
+
#include "UIThreadDispatcher.hpp"
|
|
9
10
|
#include <dispatch/dispatch.h>
|
|
10
11
|
#include <pthread.h>
|
|
11
12
|
#include <sstream>
|
|
@@ -40,4 +41,12 @@ void ThreadUtils::setThreadName(const std::string& name) {
|
|
|
40
41
|
pthread_setname_np(name.c_str());
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
bool ThreadUtils::isUIThread() {
|
|
45
|
+
return pthread_main_np() != 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
std::shared_ptr<Dispatcher> ThreadUtils::createUIThreadDispatcher() {
|
|
49
|
+
return std::make_shared<UIThreadDispatcher>();
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
} // namespace margelo::nitro
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "UIThreadDispatcher.hpp"
|
|
2
|
+
|
|
3
|
+
namespace margelo::nitro {
|
|
4
|
+
|
|
5
|
+
UIThreadDispatcher::UIThreadDispatcher() : _queue(dispatch_get_main_queue()) {}
|
|
6
|
+
|
|
7
|
+
void UIThreadDispatcher::runSync(std::function<void()>&& function) {
|
|
8
|
+
throw std::runtime_error("UIThreadDispatcher::runSync() is not implemented!");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
void UIThreadDispatcher::runAsync(std::function<void()>&& function) {
|
|
12
|
+
std::function<void()>* funcHeap = new std::function<void()>(std::move(function));
|
|
13
|
+
dispatch_async(_queue, ^{
|
|
14
|
+
(*funcHeap)();
|
|
15
|
+
delete funcHeap;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "Dispatcher.hpp"
|
|
4
|
+
#include <dispatch/dispatch.h>
|
|
5
|
+
|
|
6
|
+
namespace margelo::nitro {
|
|
7
|
+
|
|
8
|
+
class UIThreadDispatcher : public Dispatcher {
|
|
9
|
+
public:
|
|
10
|
+
UIThreadDispatcher();
|
|
11
|
+
|
|
12
|
+
void runSync(std::function<void()>&& function) override;
|
|
13
|
+
void runAsync(std::function<void()>&& function) override;
|
|
14
|
+
|
|
15
|
+
private:
|
|
16
|
+
dispatch_queue_t _queue;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace margelo::nitro
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _installWorkletsSupport = require("./worklets/installWorkletsSupport");
|
|
6
7
|
var _AnyHybridObject = require("./AnyHybridObject");
|
|
7
8
|
Object.keys(_AnyHybridObject).forEach(function (key) {
|
|
8
9
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -113,4 +114,5 @@ Object.keys(_getHostComponent).forEach(function (key) {
|
|
|
113
114
|
}
|
|
114
115
|
});
|
|
115
116
|
});
|
|
117
|
+
(0, _installWorkletsSupport.installWorkletsSupport)();
|
|
116
118
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_installWorkletsSupport","require","_AnyHybridObject","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_AnyMap","_BoxedHybridObject","_CustomType","_getHybridObjectConstructor","_HybridObject","_NitroModules","_Sync","_HybridView","_getHostComponent","installWorkletsSupport"],"sourceRoot":"../../src","s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