react-native-nitro-modules 0.24.0 → 0.24.1

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.
@@ -48,7 +48,6 @@ Pod::Spec.new do |s|
48
48
  # Public iOS-specific headers that will be exposed in modulemap (for Swift)
49
49
  "ios/core/ArrayBufferHolder.hpp",
50
50
  "ios/core/AnyMapHolder.hpp",
51
- "ios/core/HybridContext.hpp",
52
51
  "ios/core/PromiseHolder.hpp",
53
52
  "ios/utils/Result.hpp",
54
53
  "ios/utils/RuntimeError.hpp",
@@ -3,7 +3,6 @@
3
3
  #include "JAnyMap.hpp"
4
4
  #include "JAnyValue.hpp"
5
5
  #include "JArrayBuffer.hpp"
6
- #include "JHybridObjectRegistry.hpp"
7
6
  #include "JNitroModules.hpp"
8
7
  #include "JPromise.hpp"
9
8
  #include <fbjni/fbjni.h>
@@ -14,7 +13,6 @@ using namespace margelo::nitro;
14
13
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
15
14
  return facebook::jni::initialize(vm, [] {
16
15
  // 1. Initialize all core Nitro Java bindings
17
- JHybridObjectRegistry::registerNatives();
18
16
  JArrayBuffer::registerNatives();
19
17
  JAnyMap::registerNatives();
20
18
  JAnyValue::registerNatives();
@@ -18,7 +18,7 @@ using namespace facebook;
18
18
  struct JHybridObjectInitializer : public jni::JavaClass<JHybridObjectInitializer> {
19
19
  public:
20
20
  jni::local_ref<JHybridObject::javaobject> call() const {
21
- const auto method = this->getClass()->getMethod<JHybridObject::javaobject()>("initialize");
21
+ const auto method = this->javaClassStatic()->getMethod<JHybridObject::javaobject()>("initialize");
22
22
  return method(self());
23
23
  }
24
24
 
@@ -137,10 +137,5 @@ class ArrayBuffer {
137
137
  byteBuffer.rewind()
138
138
  return ArrayBuffer(byteBuffer)
139
139
  }
140
-
141
- @Deprecated("Use copy(...) instead", level = DeprecationLevel.WARNING)
142
- fun copyOf(other: ArrayBuffer): ArrayBuffer {
143
- return copy(other)
144
- }
145
140
  }
146
141
  }
@@ -67,11 +67,6 @@ public:
67
67
  * Create a new `NativeArrayBuffer` that allocates a new buffer of the given size.
68
68
  */
69
69
  static std::shared_ptr<ArrayBuffer> allocate(size_t size);
70
-
71
- [[deprecated("Use wrapBuffer(...) instead.")]]
72
- static std::shared_ptr<ArrayBuffer> makeBuffer(uint8_t* data, size_t size, DeleteFn&& deleteFunc) {
73
- return ArrayBuffer::wrap(data, size, std::move(deleteFunc));
74
- }
75
70
  };
76
71
 
77
72
  /**
@@ -161,10 +161,6 @@ public:
161
161
  _onResolvedListeners.push_back(onResolved);
162
162
  }
163
163
  }
164
- [[deprecated("Upgrade Nitro to use PromiseHolder<T> instead.")]]
165
- void addOnResolvedListenerCopy(const std::function<void(TResult)>& onResolved) {
166
- addOnResolvedListener([=](const TResult& value) { onResolved(value); });
167
- }
168
164
 
169
165
  /**
170
166
  * Add a listener that will be called when the Promise gets rejected.
@@ -185,7 +185,6 @@ struct JSIConverter<std::string> final {
185
185
  #include "JSIConverter+ArrayBuffer.hpp"
186
186
  #include "JSIConverter+Exception.hpp"
187
187
  #include "JSIConverter+Function.hpp"
188
- #include "JSIConverter+Future.hpp"
189
188
  #include "JSIConverter+HostObject.hpp"
190
189
  #include "JSIConverter+HybridObject.hpp"
191
190
  #include "JSIConverter+Optional.hpp"
@@ -9,7 +9,7 @@
9
9
  #define NitroDefines_h
10
10
 
11
11
  // Sets the version of the native Nitro core library
12
- #define NITRO_VERSION "0.24.0"
12
+ #define NITRO_VERSION "0.24.1"
13
13
 
14
14
  // Sets whether to use debug or optimized production build flags
15
15
  #ifdef DEBUG
@@ -33,13 +33,3 @@ public extension HybridObject {
33
33
  // By default, this returns `0`.
34
34
  var memorySize: Int { return 0 }
35
35
  }
36
-
37
- @available(*, deprecated, message: "HybridObjectSpec has been renamed to HybridObject. Update Nitrogen and re-generate your specs.")
38
- public typealias HybridObjectSpec = HybridObject
39
-
40
- public extension HybridObjectSpec {
41
- @available(*, deprecated, message: "getSizeOf(...) will now be default-computed. Please remove getSizeOf() from your code.")
42
- func getSizeOf<T: AnyObject>(_ instance: T) -> Int {
43
- return 0
44
- }
45
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-modules",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
4
4
  "description": "Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,45 +0,0 @@
1
- //
2
- // JHybridObjectRegistry.cpp
3
- // react-native-nitro
4
- //
5
- // Created by Marc Rousavy on 22.07.24.
6
- //
7
-
8
- #include "JHybridObjectRegistry.hpp"
9
- #include "HybridObjectRegistry.hpp"
10
- #include "JNISharedPtr.hpp"
11
- #include "NitroDefines.hpp"
12
-
13
- namespace margelo::nitro {
14
-
15
- void JHybridObjectRegistry::registerHybridObjectConstructor(jni::alias_ref<jni::JClass>, std::string hybridObjectName,
16
- jni::alias_ref<JHybridObjectInitializer> constructorFn) {
17
- auto sharedInitializer = jni::make_global(constructorFn);
18
- HybridObjectRegistry::registerHybridObjectConstructor(
19
- hybridObjectName,
20
- [sharedInitializer = std::move(sharedInitializer),
21
- hybridObjectName = std::move(hybridObjectName)]() -> std::shared_ptr<HybridObject> {
22
- // 1. Call the Java initializer function
23
- jni::local_ref<JHybridObject::javaobject> hybridObject = sharedInitializer->call();
24
- #ifdef NITRO_DEBUG
25
- if (hybridObject == nullptr) [[unlikely]] {
26
- throw std::runtime_error("Failed to create HybridObject \"" + hybridObjectName + "\" - the constructor returned null!");
27
- }
28
- #endif
29
-
30
- // 2. Make the resulting HybridObject a global (shared) reference
31
- jni::global_ref<JHybridObject::javaobject> globalHybridObject = jni::make_global(hybridObject);
32
- // 3. Create a shared_ptr from the JNI global reference
33
- std::shared_ptr<JHybridObject> sharedCppPart = JNISharedPtr::make_shared_from_jni<JHybridObject>(globalHybridObject);
34
- // 4. Up-cast to a HybridObject (kinda unsafe)
35
- std::shared_ptr<HybridObject> cast = std::static_pointer_cast<HybridObject>(sharedCppPart);
36
- return cast;
37
- });
38
- }
39
-
40
- void JHybridObjectRegistry::registerNatives() {
41
- javaClassStatic()->registerNatives({
42
- makeNativeMethod("registerHybridObjectConstructor", JHybridObjectRegistry::registerHybridObjectConstructor),
43
- });
44
- }
45
- } // namespace margelo::nitro
@@ -1,32 +0,0 @@
1
- //
2
- // JHybridObjectRegistry.hpp
3
- // react-native-nitro
4
- //
5
- // Created by Marc Rousavy on 22.07.24.
6
- //
7
-
8
- #pragma once
9
-
10
- #include "HybridObject.hpp"
11
- #include "JHybridObjectInitializer.hpp"
12
- #include <fbjni/fbjni.h>
13
-
14
- namespace margelo::nitro {
15
-
16
- using namespace facebook;
17
-
18
- struct JHybridObjectRegistry : public jni::JavaClass<JHybridObjectRegistry> {
19
- public:
20
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/core/HybridObjectRegistry;";
21
-
22
- public:
23
- [[deprecated("HybridObjects should be registered from C++ instead. Either autolink them using `nitro.json`, "
24
- "or add them manually in the C++ HybridObjectRegistry.")]]
25
- static void registerHybridObjectConstructor(jni::alias_ref<jni::JClass> clazz, std::string hybridObjectName,
26
- jni::alias_ref<JHybridObjectInitializer> constructorFn);
27
-
28
- public:
29
- static void registerNatives();
30
- };
31
-
32
- } // namespace margelo::nitro
@@ -1,17 +0,0 @@
1
- package com.margelo.nitro.core;
2
-
3
- import androidx.annotation.Keep;
4
-
5
- import com.facebook.proguard.annotations.DoNotStrip;
6
-
7
- /**
8
- * @deprecated HybridObjects should be registered from C++ instead. Either autolink them using `nitro.json`, or add them manually in the C++ `HybridObjectRegistry`.
9
- */
10
- @Keep
11
- @DoNotStrip
12
- @Deprecated(forRemoval = true)
13
- public interface HybridObjectInitializer {
14
- @Keep
15
- @DoNotStrip
16
- HybridObject initialize();
17
- }
@@ -1,27 +0,0 @@
1
- package com.margelo.nitro.core;
2
-
3
- import androidx.annotation.Keep;
4
- import com.facebook.proguard.annotations.DoNotStrip;
5
- import com.margelo.nitro.JNIOnLoad;
6
-
7
- /**
8
- * A registry that holds initializers for HybridObjects.
9
- * This will be used to initialize them from JS using `NitroModules.createHybridObject<T>(name)`.
10
- * @noinspection JavaJniMissingFunction
11
- */
12
- @Keep
13
- @DoNotStrip
14
- public class HybridObjectRegistry {
15
- static {
16
- JNIOnLoad.initializeNativeNitro();
17
- }
18
-
19
- /**
20
- * Registers the given HybridObject in the `HybridObjectRegistry`.
21
- * It will be uniquely identified via it's `hybridObjectName`, and can be initialized from
22
- * JS using `NitroModules.createHybridObject<T>(name)` - which will call the `constructorFn` here.
23
- * @deprecated HybridObjects should be registered from C++ instead. Either autolink them using `nitro.json`, or add them manually in the C++ `HybridObjectRegistry`.
24
- */
25
- @Deprecated(forRemoval = true)
26
- public static native void registerHybridObjectConstructor(String hybridObjectName, HybridObjectInitializer initializer);
27
- }
@@ -1,46 +0,0 @@
1
- //
2
- // Created by Marc Rousavy on 21.02.24.
3
- //
4
-
5
- #pragma once
6
-
7
- // Forward declare a few of the common types that might have cyclic includes.
8
- namespace margelo::nitro {
9
-
10
- template <typename T, typename Enable>
11
- struct JSIConverter;
12
- } // namespace margelo::nitro
13
-
14
- #include "JSIConverter.hpp"
15
-
16
- #include "Promise.hpp"
17
- #include <future>
18
- #include <jsi/jsi.h>
19
- #include <memory>
20
-
21
- namespace margelo::nitro {
22
-
23
- using namespace facebook;
24
-
25
- // std::future<T> <> Promise<T>
26
- template <typename TResult>
27
- struct JSIConverter<std::future<TResult>> final {
28
- [[deprecated("Use JSIConverter<std::shared_ptr<Promise<T>>> instead.")]]
29
- static inline std::future<TResult> fromJSI(jsi::Runtime& runtime, const jsi::Value& value) {
30
- auto promise = JSIConverter<std::shared_ptr<Promise<TResult>>>::fromJSI(runtime, value);
31
- return promise->await();
32
- }
33
-
34
- [[deprecated("Use JSIConverter<std::shared_ptr<Promise<T>>> instead.")]]
35
- static inline jsi::Value toJSI(jsi::Runtime& runtime, std::future<TResult>&& arg) {
36
- auto promise = Promise<TResult>::awaitFuture(std::move(arg));
37
- return JSIConverter<std::shared_ptr<Promise<TResult>>>::toJSI(runtime, promise);
38
- }
39
-
40
- [[deprecated("Use JSIConverter<std::shared_ptr<Promise<T>>> instead.")]]
41
- static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
42
- return JSIConverter<std::shared_ptr<Promise<TResult>>>::canConvert(runtime, value);
43
- }
44
- };
45
-
46
- } // namespace margelo::nitro
@@ -1,55 +0,0 @@
1
- //
2
- // HybridContext.hpp
3
- // NitroModules
4
- //
5
- // Created by Marc Rousavy on 17.07.24.
6
- //
7
-
8
- #pragma once
9
-
10
- namespace margelo::nitro {
11
- class HybridObject;
12
- }
13
-
14
- #include "HybridObject.hpp"
15
- #include "NitroLogger.hpp"
16
- #include "NitroTypeInfo.hpp"
17
- #include <memory>
18
-
19
- namespace margelo::nitro {
20
-
21
- /**
22
- * Represents contextual state for a `HybridObject`.
23
- *
24
- * This can be used in remote implementations, e.g. in a Swift implementation
25
- * to properly (weak-)reference the `HybridObject` instead of re-creating it each time.
26
- */
27
- struct [[deprecated("Update Nitrogen and re-generate your specs.")]]
28
- HybridContext final {
29
- public:
30
- std::weak_ptr<HybridObject> cppPart;
31
-
32
- public:
33
- template <typename THybridObject, typename TSwiftPart>
34
- static inline std::shared_ptr<THybridObject> getOrCreate(TSwiftPart swiftPart) noexcept {
35
- auto hybridContext = swiftPart.getHybridContext();
36
- auto hybridObject = std::dynamic_pointer_cast<THybridObject>(hybridContext.cppPart.lock());
37
- if (hybridObject != nullptr) [[likely]] {
38
- // Fast path - an existing HybridObject is still in cache! (HybridContext)
39
- return hybridObject;
40
- }
41
-
42
- // Slow path - we need to create a new HybridObject that wraps our Swift implementation.
43
- Logger::log(LogLevel::Info, TAG, "Creating new HybridObject<%s> for %s...", TypeInfo::getFriendlyTypename<THybridObject>().c_str(),
44
- TypeInfo::getFriendlyTypename<TSwiftPart>().c_str());
45
- hybridObject = std::make_shared<THybridObject>(std::forward<decltype(swiftPart)>(swiftPart));
46
- hybridContext.cppPart = hybridObject;
47
- swiftPart.setHybridContext(hybridContext);
48
- return hybridObject;
49
- }
50
-
51
- private:
52
- static constexpr auto TAG = "HybridContext";
53
- };
54
-
55
- } // namespace margelo::nitro