react-native-nitro-modules 0.27.4 → 0.27.5

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.
@@ -0,0 +1,33 @@
1
+ //
2
+ // JHybridObject.cpp
3
+ // react-native-nitro
4
+ //
5
+ // Created by Marc Rousavy on 11.08.25.
6
+ //
7
+
8
+ #include "JHybridObject.hpp"
9
+ #include "JNISharedPtr.hpp"
10
+ #include <fbjni/fbjni.h>
11
+
12
+ namespace margelo::nitro {
13
+
14
+ using namespace facebook;
15
+
16
+ std::shared_ptr<HybridObject> JHybridObject::shared() {
17
+ if (auto shared = weak_from_this().lock()) {
18
+ // We have a cached shared_ptr
19
+ return shared;
20
+ }
21
+ if (_javaPart == nullptr) [[unlikely]] {
22
+ // We don't have a _javaPart! Maybe the implementing JHybridObject
23
+ // was generated with an old version of nitrogen which doesn't call the JHybridObject(…)
24
+ // constructor yet. This is bad!
25
+ throw std::runtime_error(std::string("JHybridObject \"") + getName() +
26
+ "\" does not have a _javaPart, "
27
+ "and wasn't constructed from a std::shared_ptr! "
28
+ "Try upgrading nitrogen and re-generate your specs.");
29
+ }
30
+ return JNISharedPtr::make_shared_from_jni<JHybridObject>(_javaPart);
31
+ }
32
+
33
+ } // namespace margelo::nitro
@@ -23,9 +23,17 @@ class JHybridObject : public jni::HybridClass<JHybridObject>, public virtual Hyb
23
23
  public:
24
24
  static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/core/HybridObject;";
25
25
 
26
+ // C++ constructor (called from Java via `initHybrid()`)
27
+ explicit JHybridObject(jni::alias_ref<jhybridobject> jThis) : _javaPart(jni::make_global(jThis)) {}
28
+ // C++ default constructor used by older Nitro versions (deprecated in favor of the jThis one)
29
+ [[deprecated]] JHybridObject() = default;
26
30
  ~JHybridObject() override = default;
27
31
 
32
+ // `shared()` has custom logic because we ref-count using `jni::global_ref`!
33
+ std::shared_ptr<HybridObject> shared() override;
34
+
28
35
  private:
36
+ jni::global_ref<JHybridObject::javaobject> _javaPart;
29
37
  friend HybridBase;
30
38
  };
31
39
 
@@ -22,6 +22,16 @@ bool HybridObject::equals(const std::shared_ptr<HybridObject>& other) {
22
22
  return this == other.get();
23
23
  }
24
24
 
25
+ std::shared_ptr<HybridObject> HybridObject::shared() {
26
+ std::weak_ptr<HybridObject> weak = weak_from_this();
27
+ if (auto shared = weak.lock()) [[likely]] {
28
+ // We can lock to a shared_ptr!
29
+ return shared;
30
+ }
31
+ // We are not managed inside a shared_ptr..
32
+ throw std::runtime_error(std::string("HybridObject \"") + _name + "\" is not managed inside a std::shared_ptr - cannot access shared()!");
33
+ }
34
+
25
35
  jsi::Value HybridObject::disposeRaw(jsi::Runtime& runtime, const jsi::Value& thisArg, const jsi::Value*, size_t) {
26
36
  // 1. Dispose any resources - this might be overridden by child classes to perform manual cleanup.
27
37
  dispose();
@@ -71,7 +81,7 @@ jsi::Value HybridObject::toObject(jsi::Runtime& runtime) {
71
81
  jsi::Object object = create.call(runtime, prototype).asObject(runtime);
72
82
 
73
83
  // 5. Assign NativeState to the object so the prototype can resolve the native methods
74
- object.setNativeState(runtime, shared_from_this());
84
+ object.setNativeState(runtime, shared());
75
85
 
76
86
  // 6. Set memory size so Hermes GC knows about actual memory
77
87
  object.setExternalMemoryPressure(runtime, getExternalMemorySize());
@@ -61,13 +61,17 @@ public:
61
61
 
62
62
  public:
63
63
  /**
64
- * Get the `std::shared_ptr` instance of this HybridObject.
64
+ * Get the `std::shared_ptr` instance of this HybridObject as it's concrete type.
65
65
  * The HybridObject must be managed inside a `shared_ptr` already, otherwise this will fail.
66
66
  */
67
67
  template <typename Derived>
68
68
  std::shared_ptr<Derived> shared() {
69
- return std::dynamic_pointer_cast<Derived>(shared_from_this());
69
+ return std::dynamic_pointer_cast<Derived>(shared());
70
70
  }
71
+ /**
72
+ * Get the `std::shared_ptr` instance of this HybridObject.
73
+ */
74
+ virtual std::shared_ptr<HybridObject> shared();
71
75
 
72
76
  public:
73
77
  /**
@@ -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.27.4"
12
+ #define NITRO_VERSION "0.27.5"
13
13
 
14
14
  // Sets whether to use debug or optimized production build flags
15
15
  #ifdef DEBUG
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getHostComponent = getHostComponent;
7
7
  var _reactNative = require("react-native");
8
8
  var NativeComponentRegistry = _interopRequireWildcard(require("react-native/Libraries/NativeComponent/NativeComponentRegistry"));
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
10
  // @ts-expect-error this unfortunately isn't typed or default-exported.
12
11
 
13
12
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","NativeComponentRegistry","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","getHostComponent","name","getViewConfig","Error","Platform","OS"],"sourceRoot":"../../../src","sources":["views/getHostComponent.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,uBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAyG,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AADzG;;AAgBA;AACA;AACA;;AAsBA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACO,SAASW,gBAAgBA,CAI9BC,IAAY,EACZC,aAAsC,EACL;EACjC,IAAIxB,uBAAuB,IAAI,IAAI,EAAE;IACnC,MAAM,IAAIyB,KAAK,CACb,+CAA+CC,qBAAQ,CAACC,EAAE,GAC5D,CAAC;EACH;EACA,OAAO3B,uBAAuB,CAACU,GAAG,CAACa,IAAI,EAAEC,aAAa,CAAC;AACzD","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","NativeComponentRegistry","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","getHostComponent","name","getViewConfig","Error","Platform","OS"],"sourceRoot":"../../../src","sources":["views/getHostComponent.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,uBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAyG,SAAAE,wBAAAC,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAH,uBAAA,YAAAA,CAAAC,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AADzG;;AAgBA;AACA;AACA;;AAsBA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACO,SAASkB,gBAAgBA,CAI9BC,IAAY,EACZC,aAAsC,EACL;EACjC,IAAIvB,uBAAuB,IAAI,IAAI,EAAE;IACnC,MAAM,IAAIwB,KAAK,CACb,+CAA+CC,qBAAQ,CAACC,EAAE,GAC5D,CAAC;EACH;EACA,OAAO1B,uBAAuB,CAACc,GAAG,CAACQ,IAAI,EAAEC,aAAa,CAAC;AACzD","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-modules",
3
- "version": "0.27.4",
3
+ "version": "0.27.5",
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",