diff --git a/example/src/getTests.ts b/example/src/getTests.ts index 7deb808fb..acb994c72 100644 --- a/example/src/getTests.ts +++ b/example/src/getTests.ts @@ -839,6 +839,11 @@ export function getTests( .didNotThrow() .equals(true) ), + createTest('createArrayBuffer()', async () => + (await it(() => testObject.createArrayBufferAsync())) + .didNotThrow() + .didReturn('object') + ), // Base HybridObject inherited methods createTest('.toString()', () => diff --git a/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts b/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts index 005d5303c..1c14b4563 100644 --- a/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts +++ b/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts @@ -579,7 +579,10 @@ case ${i}: const bridge = this.getBridgeOrThrow() const makePromise = `bridge.${bridge.funcName}` const promise = getTypeAs(this.type, PromiseType) - const resolvingType = new SwiftCxxBridgedType(promise.resultingType) + const resolvingType = new SwiftCxxBridgedType( + promise.resultingType, + true + ) switch (language) { case 'c++': return `${swiftParameterName}.getFuture()` diff --git a/packages/react-native-nitro-image/android/src/main/java/com/margelo/nitro/image/HybridTestObjectKotlin.kt b/packages/react-native-nitro-image/android/src/main/java/com/margelo/nitro/image/HybridTestObjectKotlin.kt index a97b85d07..ee9a77889 100644 --- a/packages/react-native-nitro-image/android/src/main/java/com/margelo/nitro/image/HybridTestObjectKotlin.kt +++ b/packages/react-native-nitro-image/android/src/main/java/com/margelo/nitro/image/HybridTestObjectKotlin.kt @@ -158,6 +158,10 @@ class HybridTestObjectKotlin: HybridTestObjectSwiftKotlinSpec() { return ArrayBuffer.allocate(1024 * 1024 * 10) // 10 MB } + override fun createArrayBufferAsync(): Promise { + return Promise.async { createArrayBuffer() } + } + override fun getBufferLastItem(buffer: ArrayBuffer): Double { val byteBuffer = buffer.getBuffer(false) val lastItem = byteBuffer[buffer.size - 1] diff --git a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp index f948cdda2..8f1fd1e91 100644 --- a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp +++ b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp @@ -335,6 +335,10 @@ void HybridTestObjectCpp::setAllValuesTo(const std::shared_ptr& buf } } +std::future> HybridTestObjectCpp::createArrayBufferAsync() { + return std::async(std::launch::async, [this]() -> std::shared_ptr { return this->createArrayBuffer(); }); +} + std::shared_ptr HybridTestObjectCpp::newTestObject() { return std::make_shared(); } diff --git a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp index b630310a9..3ed2c1d0c 100644 --- a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp +++ b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp @@ -114,6 +114,7 @@ class HybridTestObjectCpp : public HybridTestObjectCppSpec { std::shared_ptr createArrayBuffer() override; double getBufferLastItem(const std::shared_ptr& buffer) override; void setAllValuesTo(const std::shared_ptr& buffer, double value) override; + std::future> createArrayBufferAsync() override; std::shared_ptr newTestObject() override; std::shared_ptr createBase() override; diff --git a/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift b/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift index 29867ab17..6832e0152 100644 --- a/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift +++ b/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift @@ -184,6 +184,10 @@ class HybridTestObjectSwift : HybridTestObjectSwiftKotlinSpec { return .allocate(size: 1024 * 1024 * 10) // 10 MB } + func createArrayBufferAsync() throws -> Promise { + return Promise.async { try self.createArrayBuffer() } + } + func getBufferLastItem(buffer: ArrayBufferHolder) throws -> Double { let lastBytePointer = buffer.data.advanced(by: buffer.size - 1) let lastByte = lastBytePointer.load(as: UInt8.self) diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.cpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.cpp index 9ba34084f..94e4b87f5 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.cpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.cpp @@ -418,6 +418,22 @@ namespace margelo::nitro::image { static const auto method = _javaPart->getClass()->getMethod /* buffer */, double /* value */)>("setAllValuesTo"); method(_javaPart, JArrayBuffer::wrap(buffer), value); } + std::future> JHybridTestObjectSwiftKotlinSpec::createArrayBufferAsync() { + static const auto method = _javaPart->getClass()->getMethod()>("createArrayBufferAsync"); + auto __result = method(_javaPart); + return [&]() { + auto __promise = std::make_shared>>(); + __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { + auto __result = jni::static_ref_cast(__boxedResult); + __promise->set_value(__result->cthis()->getArrayBuffer()); + }); + __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __message) { + std::runtime_error __error(__message->toStdString()); + __promise->set_exception(std::make_exception_ptr(__error)); + }); + return __promise->get_future(); + }(); + } std::shared_ptr JHybridTestObjectSwiftKotlinSpec::createChild() { static const auto method = _javaPart->getClass()->getMethod()>("createChild"); auto __result = method(_javaPart); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.hpp index 3c667b640..c71c836cb 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridTestObjectSwiftKotlinSpec.hpp @@ -101,6 +101,7 @@ namespace margelo::nitro::image { std::shared_ptr createArrayBuffer() override; double getBufferLastItem(const std::shared_ptr& buffer) override; void setAllValuesTo(const std::shared_ptr& buffer, double value) override; + std::future> createArrayBufferAsync() override; std::shared_ptr createChild() override; std::shared_ptr createBase() override; std::shared_ptr createBaseActualChild() override; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridTestObjectSwiftKotlinSpec.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridTestObjectSwiftKotlinSpec.kt index 6314bf252..2d252a409 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridTestObjectSwiftKotlinSpec.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridTestObjectSwiftKotlinSpec.kt @@ -249,6 +249,10 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() { @Keep abstract fun setAllValuesTo(buffer: ArrayBuffer, value: Double): Unit + @DoNotStrip + @Keep + abstract fun createArrayBufferAsync(): Promise + @DoNotStrip @Keep abstract fun createChild(): HybridChildSpec diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp index b34683040..8eec24de8 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp @@ -8,6 +8,10 @@ #pragma once // Forward declarations of C++ defined types +// Forward declaration of `ArrayBufferHolder` to properly resolve imports. +namespace NitroModules { class ArrayBufferHolder; } +// Forward declaration of `ArrayBuffer` to properly resolve imports. +namespace NitroModules { class ArrayBuffer; } // Forward declaration of `HybridBaseSpec` to properly resolve imports. namespace margelo::nitro::image { class HybridBaseSpec; } // Forward declaration of `HybridChildSpec` to properly resolve imports. @@ -43,6 +47,8 @@ namespace NitroImage { class HybridTestObjectSwiftKotlinSpecCxx; } #include "HybridTestObjectSwiftKotlinSpec.hpp" #include "Person.hpp" #include "Powertrain.hpp" +#include +#include #include #include #include @@ -348,6 +354,15 @@ namespace margelo::nitro::image::bridge::swift { return std::optional(value); } + // pragma MARK: PromiseHolder> + /** + * Specialized version of `PromiseHolder>`. + */ + using PromiseHolder_std__shared_ptr_ArrayBuffer__ = PromiseHolder>; + inline PromiseHolder> create_PromiseHolder_std__shared_ptr_ArrayBuffer__() { + return PromiseHolder>(); + } + // pragma MARK: std::shared_ptr /** * Specialized version of `std::shared_ptr`. diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestObjectSwiftKotlinSpecSwift.hpp b/packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestObjectSwiftKotlinSpecSwift.hpp index aba45e94a..4c91e64ba 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestObjectSwiftKotlinSpecSwift.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestObjectSwiftKotlinSpecSwift.hpp @@ -274,6 +274,10 @@ namespace margelo::nitro::image { inline void setAllValuesTo(const std::shared_ptr& buffer, double value) override { _swiftPart.setAllValuesTo(ArrayBufferHolder(buffer), std::forward(value)); } + inline std::future> createArrayBufferAsync() override { + auto __result = _swiftPart.createArrayBufferAsync(); + return __result.getFuture(); + } inline std::shared_ptr createChild() override { auto __result = _swiftPart.createChild(); return __result; diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec.swift index 7bd613054..996e11cb7 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec.swift @@ -71,6 +71,7 @@ public protocol HybridTestObjectSwiftKotlinSpec: AnyObject, HybridObjectSpec { func createArrayBuffer() throws -> ArrayBufferHolder func getBufferLastItem(buffer: ArrayBufferHolder) throws -> Double func setAllValuesTo(buffer: ArrayBufferHolder, value: Double) throws -> Void + func createArrayBufferAsync() throws -> Promise func createChild() throws -> (any HybridChildSpec) func createBase() throws -> (any HybridBaseSpec) func createBaseActualChild() throws -> (any HybridBaseSpec) diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpecCxx.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpecCxx.swift index fae409dd7..da7f74ad6 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpecCxx.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpecCxx.swift @@ -734,6 +734,23 @@ public class HybridTestObjectSwiftKotlinSpecCxx { } } + @inline(__always) + public func createArrayBufferAsync() -> bridge.PromiseHolder_std__shared_ptr_ArrayBuffer__ { + do { + let __result = try self.__implementation.createArrayBufferAsync() + return { () -> bridge.PromiseHolder_std__shared_ptr_ArrayBuffer__ in + let __promiseHolder = bridge.create_PromiseHolder_std__shared_ptr_ArrayBuffer__() + __result + .then({ __result in __promiseHolder.resolve(__result.getArrayBuffer()) }) + .catch({ __error in __promiseHolder.reject(std.string(String(describing: __error))) }) + return __promiseHolder + }() + } catch { + let __message = "\(error.localizedDescription)" + fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))") + } + } + @inline(__always) public func createChild() -> bridge.std__shared_ptr_margelo__nitro__image__HybridChildSpec_ { do { diff --git a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.cpp b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.cpp index bd6d4abe0..6b87ced87 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.cpp +++ b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.cpp @@ -76,6 +76,7 @@ namespace margelo::nitro::image { prototype.registerHybridMethod("createArrayBuffer", &HybridTestObjectCppSpec::createArrayBuffer); prototype.registerHybridMethod("getBufferLastItem", &HybridTestObjectCppSpec::getBufferLastItem); prototype.registerHybridMethod("setAllValuesTo", &HybridTestObjectCppSpec::setAllValuesTo); + prototype.registerHybridMethod("createArrayBufferAsync", &HybridTestObjectCppSpec::createArrayBufferAsync); prototype.registerHybridMethod("createChild", &HybridTestObjectCppSpec::createChild); prototype.registerHybridMethod("createBase", &HybridTestObjectCppSpec::createBase); prototype.registerHybridMethod("createBaseActualChild", &HybridTestObjectCppSpec::createBaseActualChild); diff --git a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.hpp b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.hpp index 994a25034..bc78d1376 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectCppSpec.hpp @@ -142,6 +142,7 @@ namespace margelo::nitro::image { virtual std::shared_ptr createArrayBuffer() = 0; virtual double getBufferLastItem(const std::shared_ptr& buffer) = 0; virtual void setAllValuesTo(const std::shared_ptr& buffer, double value) = 0; + virtual std::future> createArrayBufferAsync() = 0; virtual std::shared_ptr createChild() = 0; virtual std::shared_ptr createBase() = 0; virtual std::shared_ptr createBaseActualChild() = 0; diff --git a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.cpp b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.cpp index 0e14eb391..af92f5863 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.cpp +++ b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.cpp @@ -65,6 +65,7 @@ namespace margelo::nitro::image { prototype.registerHybridMethod("createArrayBuffer", &HybridTestObjectSwiftKotlinSpec::createArrayBuffer); prototype.registerHybridMethod("getBufferLastItem", &HybridTestObjectSwiftKotlinSpec::getBufferLastItem); prototype.registerHybridMethod("setAllValuesTo", &HybridTestObjectSwiftKotlinSpec::setAllValuesTo); + prototype.registerHybridMethod("createArrayBufferAsync", &HybridTestObjectSwiftKotlinSpec::createArrayBufferAsync); prototype.registerHybridMethod("createChild", &HybridTestObjectSwiftKotlinSpec::createChild); prototype.registerHybridMethod("createBase", &HybridTestObjectSwiftKotlinSpec::createBase); prototype.registerHybridMethod("createBaseActualChild", &HybridTestObjectSwiftKotlinSpec::createBaseActualChild); diff --git a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.hpp b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.hpp index 56b4978e8..efbac4961 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/shared/c++/HybridTestObjectSwiftKotlinSpec.hpp @@ -127,6 +127,7 @@ namespace margelo::nitro::image { virtual std::shared_ptr createArrayBuffer() = 0; virtual double getBufferLastItem(const std::shared_ptr& buffer) = 0; virtual void setAllValuesTo(const std::shared_ptr& buffer, double value) = 0; + virtual std::future> createArrayBufferAsync() = 0; virtual std::shared_ptr createChild() = 0; virtual std::shared_ptr createBase() = 0; virtual std::shared_ptr createBaseActualChild() = 0; diff --git a/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts b/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts index f4fd502b1..069045438 100644 --- a/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts +++ b/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts @@ -104,6 +104,7 @@ interface SharedTestObjectProps { createArrayBuffer(): ArrayBuffer getBufferLastItem(buffer: ArrayBuffer): number setAllValuesTo(buffer: ArrayBuffer, value: number): void + createArrayBufferAsync(): Promise // Inheritance createChild(): Child