@breeztech/breez-sdk-spark-react-native 0.3.3 → 0.3.4

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.
@@ -24,34 +24,14 @@ Java_com_breeztech_breezsdkspark_BreezSdkSparkReactNativeModule_nativeInstallRus
24
24
  jlong rtPtr,
25
25
  jobject callInvokerHolderJavaObj
26
26
  ) {
27
- // https://github.com/realm/realm-js/blob/main/packages/realm/binding/android/src/main/cpp/io_realm_react_RealmReactModule.cpp#L122-L145
28
- // React Native uses the fbjni library for handling JNI, which has the concept of "hybrid objects",
29
- // which are Java objects containing a pointer to a C++ object. The CallInvokerHolder, which has the
30
- // invokeAsync method we want access to, is one such hybrid object.
31
- // Rather than reworking our code to use fbjni throughout, this code unpacks the C++ object from the Java
32
- // object `callInvokerHolderJavaObj` manually, based on reverse engineering the fbjni code.
33
-
34
- // 1. Get the Java object referred to by the mHybridData field of the Java holder object
35
- auto callInvokerHolderClass = env->GetObjectClass(callInvokerHolderJavaObj);
36
- auto hybridDataField = env->GetFieldID(callInvokerHolderClass, "mHybridData", "Lcom/facebook/jni/HybridData;");
37
- auto hybridDataObj = env->GetObjectField(callInvokerHolderJavaObj, hybridDataField);
38
-
39
- // 2. Get the destructor Java object referred to by the mDestructor field from the myHybridData Java object
40
- auto hybridDataClass = env->FindClass("com/facebook/jni/HybridData");
41
- auto destructorField =
42
- env->GetFieldID(hybridDataClass, "mDestructor", "Lcom/facebook/jni/HybridData$Destructor;");
43
- auto destructorObj = env->GetObjectField(hybridDataObj, destructorField);
44
-
45
- // 3. Get the mNativePointer field from the mDestructor Java object
46
- auto destructorClass = env->FindClass("com/facebook/jni/HybridData$Destructor");
47
- auto nativePointerField = env->GetFieldID(destructorClass, "mNativePointer", "J");
48
- auto nativePointerValue = env->GetLongField(destructorObj, nativePointerField);
49
-
50
- // 4. Cast the mNativePointer back to its C++ type
51
- auto nativePointer = reinterpret_cast<facebook::react::CallInvokerHolder*>(nativePointerValue);
52
- auto jsCallInvoker = nativePointer->getCallInvoker();
27
+ using JCallInvokerHolder = facebook::react::CallInvokerHolder;
53
28
 
29
+ auto holderLocal = facebook::jni::make_local(callInvokerHolderJavaObj);
30
+ auto holderRef = facebook::jni::static_ref_cast<JCallInvokerHolder::javaobject>(holderLocal);
31
+ auto* holderCxx = holderRef->cthis();
32
+ auto jsCallInvoker = holderCxx->getCallInvoker();
54
33
  auto runtime = reinterpret_cast<jsi::Runtime *>(rtPtr);
34
+
55
35
  return breeztech_breezsdksparkreactnative::installRustCrate(*runtime, jsCallInvoker);
56
36
  }
57
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breeztech/breez-sdk-spark-react-native",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "React Native bindings for the Breez SDK - Nodeless (Spark Implementation)",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",