From 07d96a0cf67719713e07945790ba7a439c1361cb Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Thu, 9 Jan 2025 14:52:43 +0100 Subject: [PATCH] feat: New Callback implementation that extends `() -> T` in Kotlin (faster!) (#470) * feat: Add `optionalCallback` property test * fix: Remove unneeded braces for Swift functions * fix: Implement HybridTestObject * Update Podfile.lock * feat: Implement `getComplexCallback(): T`) * feat: Add actual test * Update HybridTestObjectKotlin.kt * lint * it builds like this * suppress * fix: Use `_cxx` suffix and fix missing struct constructors * fix special handling * fix: DoNotStrip only if called from C++ * fix: Fix warns * fix: Use `?.let` * fix: Fix downcasting WOOHOOO * fix: Fix upcasting now for functions * Revert the `try`/`catch` patch changes again * fix: `fromCpp()` should return the interface instead * Comments * fix: Also annotate primary constructor --- example/ios/Podfile.lock | 6 +- example/src/getTests.ts | 19 +++ .../src/syntax/kotlin/FbjniHybridObject.ts | 11 +- .../src/syntax/kotlin/KotlinCxxBridgedType.ts | 93 +++++++++-- .../nitrogen/src/syntax/kotlin/KotlinEnum.ts | 1 + .../src/syntax/kotlin/KotlinFunction.ts | 149 ++++++++++++++---- .../src/syntax/kotlin/KotlinHybridObject.ts | 43 ++--- .../src/syntax/kotlin/KotlinStruct.ts | 47 +++++- .../nitrogen/src/syntax/types/FunctionType.ts | 2 +- .../nitrogen/src/syntax/types/OptionalType.ts | 20 ++- .../nitro/image/HybridTestObjectKotlin.kt | 7 + .../cpp/HybridTestObjectCpp.cpp | 12 ++ .../cpp/HybridTestObjectCpp.hpp | 5 + .../ios/HybridTestObjectSwift.swift | 5 + .../generated/android/NitroImageOnLoad.cpp | 32 ++-- .../nitrogen/generated/android/c++/JCar.hpp | 1 + ...JFunc_std__shared_ptr_Promise_double__.hpp | 49 +++++- ...ise_std__shared_ptr_Promise_double____.hpp | 60 ++++++- ...omise_std__shared_ptr_ArrayBuffer_____.hpp | 60 ++++++- ..._std__shared_ptr_Promise_std__string__.hpp | 49 +++++- .../generated/android/c++/JFunc_void.hpp | 37 ++++- .../android/c++/JFunc_void_double.hpp | 37 ++++- .../c++/JFunc_void_std__optional_double_.hpp | 37 ++++- .../android/c++/JFunc_void_std__string.hpp | 37 ++++- .../JFunc_void_std__vector_Powertrain_.hpp | 45 +++++- .../android/c++/JHybridImageSpec.cpp | 4 +- .../c++/JHybridTestObjectSwiftKotlinSpec.cpp | 74 ++++++--- .../c++/JHybridTestObjectSwiftKotlinSpec.hpp | 3 + .../generated/android/c++/JImageFormat.hpp | 1 + .../generated/android/c++/JImageSize.hpp | 1 + .../generated/android/c++/JJsStyleStruct.hpp | 14 +- .../generated/android/c++/JOldEnum.hpp | 1 + .../generated/android/c++/JPerson.hpp | 1 + .../generated/android/c++/JPixelFormat.hpp | 1 + .../generated/android/c++/JPowertrain.hpp | 1 + .../kotlin/com/margelo/nitro/image/Car.kt | 23 +-- .../Func_std__shared_ptr_Promise_double__.kt | 55 +++++-- ...mise_std__shared_ptr_Promise_double____.kt | 55 +++++-- ...romise_std__shared_ptr_ArrayBuffer_____.kt | 55 +++++-- ...c_std__shared_ptr_Promise_std__string__.kt | 55 +++++-- .../com/margelo/nitro/image/Func_void.kt | 55 +++++-- .../margelo/nitro/image/Func_void_double.kt | 55 +++++-- .../image/Func_void_std__optional_double_.kt | 55 +++++-- .../nitro/image/Func_void_std__string.kt | 55 +++++-- .../Func_void_std__vector_Powertrain_.kt | 55 +++++-- .../com/margelo/nitro/image/HybridBaseSpec.kt | 6 +- .../margelo/nitro/image/HybridChildSpec.kt | 6 +- .../nitro/image/HybridImageFactorySpec.kt | 6 +- .../margelo/nitro/image/HybridImageSpec.kt | 12 +- .../image/HybridTestObjectSwiftKotlinSpec.kt | 86 +++++----- .../com/margelo/nitro/image/ImageSize.kt | 13 +- .../com/margelo/nitro/image/JsStyleStruct.kt | 17 +- .../kotlin/com/margelo/nitro/image/Person.kt | 13 +- .../ios/NitroImage-Swift-Cxx-Bridge.cpp | 16 +- .../ios/NitroImage-Swift-Cxx-Bridge.hpp | 62 +++++--- .../HybridTestObjectSwiftKotlinSpecSwift.hpp | 17 +- ...unc_std__shared_ptr_Promise_double__.swift | 6 +- ...e_std__shared_ptr_Promise_double____.swift | 6 +- ...ise_std__shared_ptr_ArrayBuffer_____.swift | 6 +- ...td__shared_ptr_Promise_std__string__.swift | 6 +- .../generated/ios/swift/Func_void.swift | 6 +- .../generated/ios/swift/Func_void_Car.swift | 6 +- .../ios/swift/Func_void_double.swift | 6 +- .../ios/swift/Func_void_int64_t.swift | 6 +- .../swift/Func_void_std__exception_ptr.swift | 6 +- .../Func_void_std__optional_double_.swift | 6 +- ...nc_void_std__shared_ptr_ArrayBuffer_.swift | 6 +- ...oid_std__shared_ptr_Promise_double__.swift | 6 +- ...omise_std__shared_ptr_ArrayBuffer___.swift | 6 +- .../ios/swift/Func_void_std__string.swift | 6 +- .../Func_void_std__vector_Powertrain_.swift | 6 +- .../generated/ios/swift/HybridImageSpec.swift | 2 +- .../ios/swift/HybridImageSpec_cxx.swift | 2 +- .../HybridTestObjectSwiftKotlinSpec.swift | 20 +-- .../HybridTestObjectSwiftKotlinSpec_cxx.swift | 70 ++++++-- .../generated/ios/swift/JsStyleStruct.swift | 6 +- .../shared/c++/HybridTestObjectCppSpec.cpp | 3 + .../shared/c++/HybridTestObjectCppSpec.hpp | 5 +- .../c++/HybridTestObjectSwiftKotlinSpec.cpp | 3 + .../c++/HybridTestObjectSwiftKotlinSpec.hpp | 5 +- .../src/specs/TestObject.nitro.ts | 2 + 81 files changed, 1471 insertions(+), 474 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index b6df02c56..10a107983 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1888,11 +1888,11 @@ EXTERNAL SOURCES: :path: "../../node_modules/react-native/ReactCommon/yoga" SPEC CHECKSUMS: - boost: 1dca942403ed9342f98334bf4c3621f011aa7946 - DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385 + boost: 7e761d76ca2ce687f7cc98e698152abd03a18f90 + DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb FBLazyVector: 1bf99bb46c6af9a2712592e707347315f23947aa fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be - glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a + glog: eb93e2f488219332457c3c4eafd2738ddc7e80b8 hermes-engine: 06a9c6900587420b90accc394199527c64259db4 NitroImage: b49db0212f1b50aa976b8cdd97072df904b29102 NitroModules: ff8680342cb7008646d8160ff9b30ba74c681c11 diff --git a/example/src/getTests.ts b/example/src/getTests.ts index 226b2a3f9..210f7263e 100644 --- a/example/src/getTests.ts +++ b/example/src/getTests.ts @@ -296,6 +296,20 @@ export function getTests( .didReturn(typeof OldEnum.SECOND) .equals(OldEnum.SECOND) ), + createTest('set optionalCallback, then undefined', () => + it(() => { + testObject.optionalCallback = () => {} + testObject.optionalCallback = undefined + }).didNotThrow() + ), + createTest('get optionalCallback (== self)', () => + it(() => { + testObject.optionalCallback = () => {} + return testObject.optionalCallback + }) + .didNotThrow() + .didReturn('function') + ), // Test basic functions createTest('addNumbers(5, 13) = 18', () => @@ -946,6 +960,11 @@ export function getTests( }) ).didThrow() ), + createTest('Getting complex callback from native returns a function', () => + it(() => testObject.getComplexCallback()) + .didNotThrow() + .didReturn('function') + ), // Objects createTest('getCar()', () => diff --git a/packages/nitrogen/src/syntax/kotlin/FbjniHybridObject.ts b/packages/nitrogen/src/syntax/kotlin/FbjniHybridObject.ts index 206100eb7..6e0a40a0d 100644 --- a/packages/nitrogen/src/syntax/kotlin/FbjniHybridObject.ts +++ b/packages/nitrogen/src/syntax/kotlin/FbjniHybridObject.ts @@ -217,6 +217,13 @@ function getFbjniMethodForwardImplementation( const name = getHybridObjectName(spec.name) const returnJNI = new KotlinCxxBridgedType(method.returnType) + const requiresBridge = + returnJNI.needsSpecialHandling || + method.parameters.some((p) => { + const bridged = new KotlinCxxBridgedType(p.type) + return bridged.needsSpecialHandling + }) + const methodName = requiresBridge ? `${method.name}_cxx` : method.name const returnType = returnJNI.asJniReferenceType('local') const paramsTypes = method.parameters @@ -237,14 +244,14 @@ function getFbjniMethodForwardImplementation( if (returnJNI.hasType) { // return something - we need to parse it body = ` -static const auto method = _javaPart->getClass()->getMethod<${cxxSignature}>("${method.name}"); +static const auto method = _javaPart->getClass()->getMethod<${cxxSignature}>("${methodName}"); auto __result = method(${paramsForward.join(', ')}); return ${returnJNI.parse('__result', 'kotlin', 'c++', 'c++')}; ` } else { // void method. no return body = ` -static const auto method = _javaPart->getClass()->getMethod<${cxxSignature}>("${method.name}"); +static const auto method = _javaPart->getClass()->getMethod<${cxxSignature}>("${methodName}"); method(${paramsForward.join(', ')}); ` } diff --git a/packages/nitrogen/src/syntax/kotlin/KotlinCxxBridgedType.ts b/packages/nitrogen/src/syntax/kotlin/KotlinCxxBridgedType.ts index 04bab48cd..6ba11b61a 100644 --- a/packages/nitrogen/src/syntax/kotlin/KotlinCxxBridgedType.ts +++ b/packages/nitrogen/src/syntax/kotlin/KotlinCxxBridgedType.ts @@ -37,9 +37,24 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { get needsSpecialHandling(): boolean { switch (this.type.kind) { + case 'function': + // Function needs to be converted from JFunc_... to Lambda + return true default: - return false + break + } + // check if any types this type references (e.g. underlying optional, array element, ...) + // needs special handling. if yes, we need it as well + const referencedTypes = getReferencedTypes(this.type) + .filter((t) => t !== this.type) + .map((t) => new KotlinCxxBridgedType(t)) + for (const type of referencedTypes) { + if (type.needsSpecialHandling) { + return true + } } + // no special handling needed + return false } getRequiredImports(): SourceImport[] { @@ -204,9 +219,10 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { return this.type.getCode(language) } case 'array': + const array = getTypeAs(this.type, ArrayType) + const bridgedItem = new KotlinCxxBridgedType(array.itemType) switch (language) { case 'c++': - const array = getTypeAs(this.type, ArrayType) switch (array.itemType.kind) { case 'number': return 'jni::JArrayDouble' @@ -215,9 +231,10 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { case 'bigint': return 'jni::JArrayLong' default: - const bridged = new KotlinCxxBridgedType(array.itemType) - return `jni::JArrayClass<${bridged.getTypeCode(language)}>` + return `jni::JArrayClass<${bridgedItem.getTypeCode(language)}>` } + case 'kotlin': + return `Array<${bridgedItem.getTypeCode(language)}>` default: return this.type.getCode(language) } @@ -313,9 +330,12 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { return this.type.getCode(language) } case 'optional': { + const optional = getTypeAs(this.type, OptionalType) + const bridgedWrappingType = new KotlinCxxBridgedType( + optional.wrappingType + ) switch (language) { case 'c++': - const optional = getTypeAs(this.type, OptionalType) switch (optional.wrappingType.kind) { // primitives need to be boxed to make them nullable case 'number': @@ -325,9 +345,10 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { return boxed default: // all other types can be nullable as they are objects. - const bridge = new KotlinCxxBridgedType(optional.wrappingType) - return bridge.getTypeCode('c++') + return bridgedWrappingType.getTypeCode('c++') } + case 'kotlin': + return `${bridgedWrappingType.getTypeCode(language)}?` default: return this.type.getCode(language) } @@ -419,9 +440,9 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { switch (language) { case 'c++': const func = getTypeAs(this.type, FunctionType) - return `J${func.specializationName}::fromCpp(${parameterName})` + return `J${func.specializationName}_cxx::fromCpp(${parameterName})` case 'kotlin': - return `${parameterName}.toLambda()` + return parameterName default: return parameterName } @@ -442,6 +463,12 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { switch (language) { case 'c++': return `${parameterName}.has_value() ? ${bridge.parseFromCppToKotlin(`${parameterName}.value()`, 'c++', true)} : nullptr` + case 'kotlin': + if (bridge.needsSpecialHandling) { + return `${parameterName}?.let { ${bridge.parseFromCppToKotlin('it', language, isBoxed)} }` + } else { + return parameterName + } default: return parameterName } @@ -488,11 +515,11 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { } } case 'array': { + const array = getTypeAs(this.type, ArrayType) + const arrayType = this.getTypeCode('c++') + const bridge = new KotlinCxxBridgedType(array.itemType) switch (language) { case 'c++': { - const array = getTypeAs(this.type, ArrayType) - const arrayType = this.getTypeCode('c++') - const bridge = new KotlinCxxBridgedType(array.itemType) switch (array.itemType.kind) { case 'number': case 'boolean': @@ -516,7 +543,7 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { jni::local_ref<${arrayType}> __array = ${arrayType}::newArray(__size); for (size_t __i = 0; __i < __size; __i++) { const auto& __element = ${parameterName}[__i]; - __array->setElement(__i, *${bridge.parseFromCppToKotlin('__element', 'c++')}); + __array->setElement(__i, *${indent(bridge.parseFromCppToKotlin('__element', 'c++'), ' ')}); } return __array; }() @@ -524,6 +551,12 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { } } } + case 'kotlin': + if (bridge.needsSpecialHandling) { + return `${parameterName}.map { ${bridge.parseFromCppToKotlin('it', language, isBoxed)} }` + } else { + return parameterName + } default: return parameterName } @@ -657,14 +690,44 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> { true ) return `${parameterName} != nullptr ? std::make_optional(${parsed}) : std::nullopt` + case 'kotlin': + if (bridge.needsSpecialHandling) { + return `${parameterName}?.let { ${bridge.parseFromKotlinToCpp('it', language, isBoxed)} }` + } else { + return parameterName + } default: return parameterName } } case 'function': { + const functionType = getTypeAs(this.type, FunctionType) switch (language) { - case 'c++': - return `${parameterName}->cthis()->getFunction()` + case 'c++': { + const returnType = functionType.returnType.getCode('c++') + const params = functionType.parameters.map( + (p) => `${p.getCode('c++')} ${p.escapedName}` + ) + const paramsForward = functionType.parameters.map( + (p) => p.escapedName + ) + const jniType = `J${functionType.specializationName}_cxx` + return ` +[&]() -> ${functionType.getCode('c++')} { + if (${parameterName}->isInstanceOf(${jniType}::javaClassStatic())) [[likely]] { + auto downcast = jni::static_ref_cast<${jniType}::javaobject>(${parameterName}); + return downcast->cthis()->getFunction(); + } else { + return [${parameterName}](${params.join(', ')}) -> ${returnType} { + return ${parameterName}->invoke(${paramsForward}); + }; + } +}() + `.trim() + } + case 'kotlin': { + return `${functionType.specializationName}_java(${parameterName})` + } default: return parameterName } diff --git a/packages/nitrogen/src/syntax/kotlin/KotlinEnum.ts b/packages/nitrogen/src/syntax/kotlin/KotlinEnum.ts index 2ca6d99e1..c5f4b83fa 100644 --- a/packages/nitrogen/src/syntax/kotlin/KotlinEnum.ts +++ b/packages/nitrogen/src/syntax/kotlin/KotlinEnum.ts @@ -60,6 +60,7 @@ namespace ${cxxNamespace} { * Convert this Java/Kotlin-based enum to the C++ enum ${enumType.enumName}. */ [[maybe_unused]] + [[nodiscard]] ${enumType.enumName} toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldOrdinal = clazz->getField("_ordinal"); diff --git a/packages/nitrogen/src/syntax/kotlin/KotlinFunction.ts b/packages/nitrogen/src/syntax/kotlin/KotlinFunction.ts index 5f8221c8e..a81c39c94 100644 --- a/packages/nitrogen/src/syntax/kotlin/KotlinFunction.ts +++ b/packages/nitrogen/src/syntax/kotlin/KotlinFunction.ts @@ -14,7 +14,11 @@ export function createKotlinFunction(functionType: FunctionType): SourceFile[] { const kotlinParams = functionType.parameters.map( (p) => `${p.escapedName}: ${p.getCode('kotlin')}` ) - const lambdaSignature = `(${kotlinParams.join(', ')}) -> ${kotlinReturnType}` + const kotlinParamTypes = functionType.parameters.map((p) => + p.getCode('kotlin') + ) + const kotlinParamsForward = functionType.parameters.map((p) => p.escapedName) + const lambdaSignature = `(${kotlinParamTypes.join(', ')}) -> ${kotlinReturnType}` const kotlinCode = ` ${createFileMetadataString(`${name}.kt`)} @@ -27,14 +31,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback \`${functionType.jsName}\`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface ${name}: ${lambdaSignature} { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(${kotlinParams.join(', ')}): ${kotlinReturnType} +} + /** * Represents the JavaScript callback \`${functionType.jsName}\`. * This is implemented in C++, via a \`std::function<...>\`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class ${name} { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class ${name}_cxx: ${name} { @DoNotStrip @Keep private val mHybridData: HybridData @@ -45,23 +72,37 @@ class ${name} { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): ${lambdaSignature} = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(${kotlinParams.join(', ')}): ${kotlinReturnType} + external override fun invoke(${kotlinParams.join(', ')}): ${kotlinReturnType} +} + +/** + * Represents the JavaScript callback \`${functionType.jsName}\`. + * This is implemented in Java/Kotlin, via a \`${lambdaSignature}\`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class ${name}_java(private val function: ${lambdaSignature}): ${name} { + @DoNotStrip + @Keep + override fun invoke(${kotlinParams.join(', ')}): ${kotlinReturnType} { + return this.function(${kotlinParamsForward.join(', ')}) + } } `.trim() + const jniInterfaceDescriptor = NitroConfig.getAndroidPackage('c++/jni', name) + const jniClassDescriptor = NitroConfig.getAndroidPackage( + 'c++/jni', + `${name}_cxx` + ) const bridgedReturn = new KotlinCxxBridgedType(functionType.returnType) + const cxxNamespace = NitroConfig.getCxxNamespace('c++') + const typename = functionType.getCode('c++') + // call() Java -> C++ const cppParams = functionType.parameters.map((p) => { const bridge = new KotlinCxxBridgedType(p) const type = bridge.asJniReferenceType('alias') @@ -71,19 +112,49 @@ class ${name} { const bridge = new KotlinCxxBridgedType(p) return bridge.parseFromKotlinToCpp(p.escapedName, 'c++', false) }) - const jniClassDescriptor = NitroConfig.getAndroidPackage('c++/jni', name) - const cxxNamespace = NitroConfig.getCxxNamespace('c++') - const typename = functionType.getCode('c++') - let callBody: string + + // call() C++ -> Java + const jniParams = functionType.parameters.map((p) => { + if (p.canBePassedByReference) { + return `const ${p.getCode('c++')}& ${p.escapedName}` + } else { + return `${p.getCode('c++')} ${p.escapedName}` + } + }) + const jniParamsForward = [ + 'self()', + ...functionType.parameters.map((p) => { + const bridge = new KotlinCxxBridgedType(p) + return bridge.parseFromCppToKotlin(p.escapedName, 'c++', false) + }), + ] + const jniSignature = `${bridgedReturn.asJniReferenceType('local')}(${functionType.parameters + .map((p) => { + const bridge = new KotlinCxxBridgedType(p) + return `${bridge.asJniReferenceType('alias')} /* ${p.escapedName} */` + }) + .join(', ')})` + + let cppCallBody: string + let jniCallBody: string if (functionType.returnType.kind === 'void') { // It returns void - callBody = `_func(${indent(paramsForward.join(', '), ' ')});` + cppCallBody = `_func(${indent(paramsForward.join(', '), ' ')});` + jniCallBody = ` +static const auto method = getClass()->getMethod<${jniSignature}>("invoke"); +method(${jniParamsForward.join(', ')}); + `.trim() } else { // It returns a type! - callBody = ` + cppCallBody = ` ${functionType.returnType.getCode('c++')} __result = _func(${indent(paramsForward.join(', '), ' ')}); return ${bridgedReturn.parseFromCppToKotlin('__result', 'c++')}; `.trim() + jniCallBody = ` +static const auto method = getClass()->getMethod<${jniSignature}>("invoke"); +auto __result = method(${jniParamsForward.join(', ')}); +return ${bridgedReturn.parseFromKotlinToCpp('__result', 'c++', false)}; + `.trim() } const bridged = new KotlinCxxBridgedType(functionType) @@ -107,21 +178,41 @@ namespace ${cxxNamespace} { using namespace facebook; /** - * C++ representation of the callback ${name}. - * This is a Kotlin \`${functionType.getCode('kotlin')}\`, backed by a \`std::function<...>\`. + * Represents the Java/Kotlin callback \`${functionType.getCode('kotlin')}\`. + * This can be passed around between C++ and Java/Kotlin. + */ + struct J${name}: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "L${jniInterfaceDescriptor};"; + + public: + /** + * Invokes the function this \`J${name}\` instance holds through JNI. + */ + ${functionType.returnType.getCode('c++')} invoke(${jniParams.join(', ')}) const { + ${indent(jniCallBody, ' ')} + } + }; + + /** + * An implementation of ${name} that is backed by a C++ implementation (using \`std::function<...>\`) */ - struct J${name} final: public jni::HybridClass { + struct J${name}_cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const ${typename}& func) { - return J${name}::newObjectCxxArgs(func); + return J${name}_cxx::newObjectCxxArgs(func); } public: - ${bridgedReturn.asJniReferenceType('local')} call(${cppParams.join(', ')}) { - ${indent(callBody, ' ')} + /** + * Invokes the C++ \`std::function<...>\` this \`J${name}_cxx\` instance holds. + */ + ${bridgedReturn.asJniReferenceType('local')} invoke_cxx(${cppParams.join(', ')}) { + ${indent(cppCallBody, ' ')} } public: + [[nodiscard]] inline const ${typename}& getFunction() const { return _func; } @@ -129,11 +220,11 @@ namespace ${cxxNamespace} { public: static auto constexpr kJavaDescriptor = "L${jniClassDescriptor};"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", J${name}::call)}); + registerHybrid({makeNativeMethod("invoke", J${name}_cxx::invoke_cxx)}); } private: - explicit J${name}(const ${typename}& func): _func(func) { } + explicit J${name}_cxx(const ${typename}& func): _func(func) { } private: friend HybridBase; @@ -146,7 +237,7 @@ namespace ${cxxNamespace} { // Make sure we register all native JNI methods on app startup addJNINativeRegistration({ namespace: cxxNamespace, - className: `J${name}`, + className: `J${name}_cxx`, import: { name: `J${name}.hpp`, space: 'user', diff --git a/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts b/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts index 3e676036a..e082f7eed 100644 --- a/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts +++ b/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts @@ -7,7 +7,6 @@ import type { HybridObjectSpec } from '../HybridObjectSpec.js' import { Method } from '../Method.js' import { Property } from '../Property.js' import type { SourceFile } from '../SourceFile.js' -import { type Type } from '../types/Type.js' import { createFbjniHybridObject } from './FbjniHybridObject.js' import { KotlinCxxBridgedType } from './KotlinCxxBridgedType.js' @@ -52,7 +51,11 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) abstract class ${name.HybridTSpec}: ${kotlinBase}() { @DoNotStrip private var mHybridData: HybridData = initHybrid() @@ -116,20 +119,15 @@ abstract class ${name.HybridTSpec}: ${kotlinBase}() { return files } -function requiresSpecialBridging(type: Type): boolean { - return ( - type.getCode('kotlin') !== - new KotlinCxxBridgedType(type).getTypeCode('kotlin') - ) -} - function getMethodForwardImplementation(method: Method): string { const bridgedReturn = new KotlinCxxBridgedType(method.returnType) const requiresBridge = - requiresSpecialBridging(method.returnType) || - method.parameters.some((p) => requiresSpecialBridging(p.type)) + bridgedReturn.needsSpecialHandling || + method.parameters.some((p) => { + const bridged = new KotlinCxxBridgedType(p.type) + return bridged.needsSpecialHandling + }) - const code = method.getCode('kotlin', { doNotStrip: true, virtual: true }) if (requiresBridge) { const paramsSignature = method.parameters.map((p) => { const bridge = new KotlinCxxBridgedType(p.type) @@ -143,33 +141,32 @@ function getMethodForwardImplementation(method: Method): string { '__result', 'kotlin' ) + const code = method.getCode('kotlin', { virtual: true }) return ` ${code} @DoNotStrip @Keep -private fun ${method.name}(${paramsSignature.join(', ')}): ${bridgedReturn.getTypeCode('kotlin')} { +private fun ${method.name}_cxx(${paramsSignature.join(', ')}): ${bridgedReturn.getTypeCode('kotlin')} { val __result = ${method.name}(${paramsForward.join(', ')}) return ${returnForward} } `.trim() } else { + const code = method.getCode('kotlin', { doNotStrip: true, virtual: true }) return code } } function getPropertyForwardImplementation(property: Property): string { - const code = property.getCode('kotlin', { doNotStrip: true, virtual: true }) - if (requiresSpecialBridging(property.type)) { - const bridged = new KotlinCxxBridgedType(property.type) - + const bridged = new KotlinCxxBridgedType(property.type) + if (bridged.needsSpecialHandling) { let keyword = property.isReadonly ? 'val' : 'var' - let modifiers: string[] = [] - modifiers.push('@get:DoNotStrip', '@get:Keep') - if (!property.isReadonly) modifiers.push('@set:DoNotStrip', '@set:Keep') let lines: string[] = [] lines.push( ` +@Keep +@DoNotStrip get() { return ${indent(bridged.parseFromKotlinToCpp(property.name, 'kotlin'), ' ')} } @@ -178,19 +175,23 @@ get() { if (!property.isReadonly) { lines.push( ` +@Keep +@DoNotStrip set(value) { ${property.name} = ${indent(bridged.parseFromCppToKotlin('value', 'kotlin'), ' ')} } `.trim() ) } + const code = property.getCode('kotlin', { virtual: true }) return ` ${code} -private ${keyword} ${property.name}: ${bridged.getTypeCode('kotlin')} +private ${keyword} ${property.name}_cxx: ${bridged.getTypeCode('kotlin')} ${indent(lines.join('\n'), ' ')} `.trim() } else { + const code = property.getCode('kotlin', { doNotStrip: true, virtual: true }) return code } } diff --git a/packages/nitrogen/src/syntax/kotlin/KotlinStruct.ts b/packages/nitrogen/src/syntax/kotlin/KotlinStruct.ts index aa9ef3b32..ed8c5d4a4 100644 --- a/packages/nitrogen/src/syntax/kotlin/KotlinStruct.ts +++ b/packages/nitrogen/src/syntax/kotlin/KotlinStruct.ts @@ -12,6 +12,41 @@ export function createKotlinStruct(structType: StructType): SourceFile[] { const values = structType.properties.map( (p) => `val ${p.escapedName}: ${p.getCode('kotlin')}` ) + let secondaryConstructor: string + const needsSpecialHandling = structType.properties.some( + (p) => new KotlinCxxBridgedType(p).needsSpecialHandling + ) + if (needsSpecialHandling) { + const params = structType.properties.map((p) => { + const bridged = new KotlinCxxBridgedType(p) + return `${p.escapedName}: ${bridged.getTypeCode('kotlin')}` + }) + const paramsForward = structType.properties.map((p) => { + const bridged = new KotlinCxxBridgedType(p) + if (bridged.needsSpecialHandling) { + // We need special parsing for this type + const parsed = bridged.parseFromCppToKotlin( + p.escapedName, + 'kotlin', + false + ) + // we explicitly `as`-cast this to avoid ambiguous upcasts/cyclic this() calls. + return `${parsed} as ${p.getCode('kotlin')}` + } else { + return p.escapedName + } + }) + secondaryConstructor = ` +@DoNotStrip +@Keep +@Suppress("unused") +private constructor(${indent(params.join(', '), 20)}) + : this(${indent(paramsForward.join(', '), 20)}) + `.trim() + } else { + secondaryConstructor = `/* main constructor */` + } + const code = ` ${createFileMetadataString(`${structType.structName}.kt`)} @@ -26,9 +61,14 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -data class ${structType.structName}( - ${indent(values.join(',\n'), ' ')} -) +data class ${structType.structName} + @DoNotStrip + @Keep + constructor( + ${indent(values.join(',\n'), ' ')} + ) { + ${indent(secondaryConstructor, ' ')} +} `.trim() const cxxNamespace = NitroConfig.getCxxNamespace('c++') @@ -76,6 +116,7 @@ namespace ${cxxNamespace} { * Convert this Java/Kotlin-based struct to the C++ struct ${structType.structName} by copying all values to C++. */ [[maybe_unused]] + [[nodiscard]] ${structType.structName} toCpp() const { ${indent(jniStructInitializerBody, ' ')} } diff --git a/packages/nitrogen/src/syntax/types/FunctionType.ts b/packages/nitrogen/src/syntax/types/FunctionType.ts index 66ae2617d..8abdda760 100644 --- a/packages/nitrogen/src/syntax/types/FunctionType.ts +++ b/packages/nitrogen/src/syntax/types/FunctionType.ts @@ -113,7 +113,7 @@ export class FunctionType implements Type { }) .join(', ') const returnType = this.returnType.getCode(language) - return `((${params}) -> ${returnType})` + return `(${params}) -> ${returnType}` } case 'kotlin': { const params = this.parameters diff --git a/packages/nitrogen/src/syntax/types/OptionalType.ts b/packages/nitrogen/src/syntax/types/OptionalType.ts index d8b3ee2f1..23d1bf6b2 100644 --- a/packages/nitrogen/src/syntax/types/OptionalType.ts +++ b/packages/nitrogen/src/syntax/types/OptionalType.ts @@ -16,6 +16,14 @@ export class OptionalType implements Type { get kind(): TypeKind { return 'optional' } + get needsBraces(): boolean { + switch (this.wrappingType.kind) { + case 'function': + return true + default: + return false + } + } getCode(language: Language): string { const wrapping = this.wrappingType.getCode(language) @@ -23,9 +31,17 @@ export class OptionalType implements Type { case 'c++': return `std::optional<${wrapping}>` case 'swift': - return `${wrapping}?` + if (this.needsBraces) { + return `(${wrapping})?` + } else { + return `${wrapping}?` + } case 'kotlin': - return `${wrapping}?` + if (this.needsBraces) { + return `(${wrapping})?` + } else { + return `${wrapping}?` + } default: throw new Error( `Language ${language} is not yet supported for OptionalType!` 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 ac4b5b38e..124c941e3 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 @@ -28,6 +28,7 @@ class HybridTestObjectKotlin: HybridTestObjectSwiftKotlinSpec() { override var optionalArray: Array? = null override var optionalEnum: Powertrain? = null override var optionalOldEnum: OldEnum? = null + override var optionalCallback: ((value: Double) -> Unit)? = null override fun simpleFunc() { // do nothing @@ -218,6 +219,12 @@ class HybridTestObjectKotlin: HybridTestObjectSwiftKotlinSpec() { } } + override fun getComplexCallback(): (Double) -> Unit { + return { value -> + Log.i(TAG, "Callback called with $value.") + } + } + override fun getCar(): Car { return Car(2018.0, "Lamborghini", "Huracán", 640.0, Powertrain.GAS, null, true) } diff --git a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp index 2a53435f1..27d83836f 100644 --- a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp +++ b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.cpp @@ -125,6 +125,14 @@ void HybridTestObjectCpp::setOptionalOldEnum(std::optional optionalOldE _optionalOldEnum = optionalOldEnum; } +std::optional> HybridTestObjectCpp::getOptionalCallback() { + return _optionalCallback; +} + +void HybridTestObjectCpp::setOptionalCallback(const std::optional>& callback) { + _optionalCallback = callback; +} + // Methods double HybridTestObjectCpp::addNumbers(double a, double b) { return a + b; @@ -310,6 +318,10 @@ std::shared_ptr>> HybridTestObjectCpp::call }); } +std::function HybridTestObjectCpp::getComplexCallback() { + return [](double value) { Logger::log(LogLevel::Info, TAG, "Callback called with %f", value); }; +} + std::shared_ptr> HybridTestObjectCpp::getValueFromJSCallbackAndWait(const std::function>()>& getValue) { return Promise::async([=]() -> double { diff --git a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp index e031e1771..e6fbcea08 100644 --- a/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp +++ b/packages/react-native-nitro-image/cpp/HybridTestObjectCpp.hpp @@ -30,6 +30,7 @@ class HybridTestObjectCpp : public HybridTestObjectCppSpec { std::optional> _optionalHybrid; std::optional _optionalEnum; std::optional _optionalOldEnum; + std::optional> _optionalCallback; private: static inline uint64_t calculateFibonacci(int count) noexcept { @@ -70,6 +71,8 @@ class HybridTestObjectCpp : public HybridTestObjectCppSpec { void setOptionalEnum(std::optional optionalEnum) override; std::optional getOptionalOldEnum() override; void setOptionalOldEnum(std::optional optionalOldEnum) override; + std::optional> getOptionalCallback() override; + void setOptionalCallback(const std::optional>& callback) override; public: // Methods @@ -117,6 +120,8 @@ class HybridTestObjectCpp : public HybridTestObjectCppSpec { callbackAsyncPromise(const std::function>>>()>& callback) override; std::shared_ptr>> callbackAsyncPromiseBuffer( const std::function>>>>()>& callback) override; + std::function getComplexCallback() override; + std::shared_ptr> getValueFromJsCallback(const std::function>()>& callback, const std::function& andThenCall) override; diff --git a/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift b/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift index 28292da26..30ecdcc4c 100644 --- a/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift +++ b/packages/react-native-nitro-image/ios/HybridTestObjectSwift.swift @@ -33,6 +33,8 @@ class HybridTestObjectSwift : HybridTestObjectSwiftKotlinSpec { var optionalOldEnum: OldEnum? = nil + var optionalCallback: ((Double) -> Void)? = nil + func simpleFunc() throws { // do nothing } @@ -98,6 +100,9 @@ class HybridTestObjectSwift : HybridTestObjectSwiftKotlinSpec { } } + func getComplexCallback() throws -> (Double) -> Void { + return { value in print("Callback called with \(value).") } + } func bounceStrings(array: [String]) throws -> [String] { return array diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/NitroImageOnLoad.cpp b/packages/react-native-nitro-image/nitrogen/generated/android/NitroImageOnLoad.cpp index 3ff4eaff7..634ac2f87 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/NitroImageOnLoad.cpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/NitroImageOnLoad.cpp @@ -19,6 +19,7 @@ #include "JFunc_void_std__string.hpp" #include "JHybridImageFactorySpec.hpp" #include "JHybridTestObjectSwiftKotlinSpec.hpp" +#include "JFunc_void_double.hpp" #include "JFunc_void_std__vector_Powertrain_.hpp" #include "JFunc_void.hpp" #include "JFunc_void_std__optional_double_.hpp" @@ -26,7 +27,6 @@ #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.hpp" #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.hpp" #include "JFunc_std__shared_ptr_Promise_std__string__.hpp" -#include "JFunc_void_double.hpp" #include "JHybridBaseSpec.hpp" #include "JHybridChildSpec.hpp" #include @@ -43,22 +43,24 @@ int initialize(JavaVM* vm) { return facebook::jni::initialize(vm, [] { // Register native JNI methods margelo::nitro::image::JHybridImageSpec::registerNatives(); - margelo::nitro::image::JFunc_void_std__string::registerNatives(); + margelo::nitro::image::JFunc_void_std__string_cxx::registerNatives(); margelo::nitro::image::JHybridImageFactorySpec::registerNatives(); margelo::nitro::image::JHybridTestObjectSwiftKotlinSpec::registerNatives(); - margelo::nitro::image::JFunc_void_std__vector_Powertrain_::registerNatives(); - margelo::nitro::image::JFunc_void::registerNatives(); - margelo::nitro::image::JFunc_void::registerNatives(); - margelo::nitro::image::JFunc_void::registerNatives(); - margelo::nitro::image::JFunc_void::registerNatives(); - margelo::nitro::image::JFunc_void_std__optional_double_::registerNatives(); - margelo::nitro::image::JFunc_std__shared_ptr_Promise_double__::registerNatives(); - margelo::nitro::image::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____::registerNatives(); - margelo::nitro::image::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____::registerNatives(); - margelo::nitro::image::JFunc_std__shared_ptr_Promise_double__::registerNatives(); - margelo::nitro::image::JFunc_std__shared_ptr_Promise_std__string__::registerNatives(); - margelo::nitro::image::JFunc_void_std__string::registerNatives(); - margelo::nitro::image::JFunc_void_double::registerNatives(); + margelo::nitro::image::JFunc_void_double_cxx::registerNatives(); + margelo::nitro::image::JFunc_void_double_cxx::registerNatives(); + margelo::nitro::image::JFunc_void_std__vector_Powertrain__cxx::registerNatives(); + margelo::nitro::image::JFunc_void_cxx::registerNatives(); + margelo::nitro::image::JFunc_void_cxx::registerNatives(); + margelo::nitro::image::JFunc_void_cxx::registerNatives(); + margelo::nitro::image::JFunc_void_cxx::registerNatives(); + margelo::nitro::image::JFunc_void_std__optional_double__cxx::registerNatives(); + margelo::nitro::image::JFunc_std__shared_ptr_Promise_double___cxx::registerNatives(); + margelo::nitro::image::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx::registerNatives(); + margelo::nitro::image::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx::registerNatives(); + margelo::nitro::image::JFunc_std__shared_ptr_Promise_double___cxx::registerNatives(); + margelo::nitro::image::JFunc_std__shared_ptr_Promise_std__string___cxx::registerNatives(); + margelo::nitro::image::JFunc_void_std__string_cxx::registerNatives(); + margelo::nitro::image::JFunc_void_double_cxx::registerNatives(); margelo::nitro::image::JHybridBaseSpec::registerNatives(); margelo::nitro::image::JHybridChildSpec::registerNatives(); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JCar.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JCar.hpp index db06c58ee..c3e457351 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JCar.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JCar.hpp @@ -33,6 +33,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based struct to the C++ struct Car by copying all values to C++. */ [[maybe_unused]] + [[nodiscard]] Car toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldYear = clazz->getField("year"); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_double__.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_double__.hpp index 684b54fb9..8fce66e57 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_double__.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_double__.hpp @@ -19,17 +19,49 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_std__shared_ptr_Promise_double__. - * This is a Kotlin `() -> Promise`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `() -> Promise`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_std__shared_ptr_Promise_double__ final: public jni::HybridClass { + struct JFunc_std__shared_ptr_Promise_double__: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_double__;"; + + public: + /** + * Invokes the function this `JFunc_std__shared_ptr_Promise_double__` instance holds through JNI. + */ + std::shared_ptr> invoke() const { + static const auto method = getClass()->getMethod()>("invoke"); + auto __result = method(self()); + return [&]() { + auto __promise = Promise::create(); + __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { + auto __result = jni::static_ref_cast(__boxedResult); + __promise->resolve(__result->value()); + }); + __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { + jni::JniException __jniError(__throwable); + __promise->reject(std::make_exception_ptr(__jniError)); + }); + return __promise; + }(); + } + }; + + /** + * An implementation of Func_std__shared_ptr_Promise_double__ that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_std__shared_ptr_Promise_double___cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function>()>& func) { - return JFunc_std__shared_ptr_Promise_double__::newObjectCxxArgs(func); + return JFunc_std__shared_ptr_Promise_double___cxx::newObjectCxxArgs(func); } public: - jni::local_ref call() { + /** + * Invokes the C++ `std::function<...>` this `JFunc_std__shared_ptr_Promise_double___cxx` instance holds. + */ + jni::local_ref invoke_cxx() { std::shared_ptr> __result = _func(); return [&]() { jni::local_ref __localPromise = JPromise::create(); @@ -46,18 +78,19 @@ namespace margelo::nitro::image { } public: + [[nodiscard]] inline const std::function>()>& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_double__;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_double___cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_std__shared_ptr_Promise_double__::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_std__shared_ptr_Promise_double___cxx::invoke_cxx)}); } private: - explicit JFunc_std__shared_ptr_Promise_double__(const std::function>()>& func): _func(func) { } + explicit JFunc_std__shared_ptr_Promise_double___cxx(const std::function>()>& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.hpp index df79df6ed..6db345824 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.hpp @@ -19,17 +19,60 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____. - * This is a Kotlin `() -> Promise>`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `() -> Promise>`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ final: public jni::HybridClass { + struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____;"; + + public: + /** + * Invokes the function this `JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____` instance holds through JNI. + */ + std::shared_ptr>>> invoke() const { + static const auto method = getClass()->getMethod()>("invoke"); + auto __result = method(self()); + return [&]() { + auto __promise = Promise>>::create(); + __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { + auto __result = jni::static_ref_cast(__boxedResult); + __promise->resolve([&]() { + auto __promise = Promise::create(); + __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { + auto __result = jni::static_ref_cast(__boxedResult); + __promise->resolve(__result->value()); + }); + __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { + jni::JniException __jniError(__throwable); + __promise->reject(std::make_exception_ptr(__jniError)); + }); + return __promise; + }()); + }); + __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { + jni::JniException __jniError(__throwable); + __promise->reject(std::make_exception_ptr(__jniError)); + }); + return __promise; + }(); + } + }; + + /** + * An implementation of Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function>>>()>& func) { - return JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____::newObjectCxxArgs(func); + return JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx::newObjectCxxArgs(func); } public: - jni::local_ref call() { + /** + * Invokes the C++ `std::function<...>` this `JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx` instance holds. + */ + jni::local_ref invoke_cxx() { std::shared_ptr>>> __result = _func(); return [&]() { jni::local_ref __localPromise = JPromise::create(); @@ -57,18 +100,19 @@ namespace margelo::nitro::image { } public: + [[nodiscard]] inline const std::function>>>()>& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx::invoke_cxx)}); } private: - explicit JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(const std::function>>>()>& func): _func(func) { } + explicit JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx(const std::function>>>()>& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.hpp index 37863b857..e795cd07d 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.hpp @@ -22,17 +22,60 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____. - * This is a Kotlin `() -> Promise>`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `() -> Promise>`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ final: public jni::HybridClass { + struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____;"; + + public: + /** + * Invokes the function this `JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____` instance holds through JNI. + */ + std::shared_ptr>>>> invoke() const { + static const auto method = getClass()->getMethod()>("invoke"); + auto __result = method(self()); + return [&]() { + auto __promise = Promise>>>::create(); + __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { + auto __result = jni::static_ref_cast(__boxedResult); + __promise->resolve([&]() { + auto __promise = Promise>::create(); + __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { + auto __result = jni::static_ref_cast(__boxedResult); + __promise->resolve(__result->cthis()->getArrayBuffer()); + }); + __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { + jni::JniException __jniError(__throwable); + __promise->reject(std::make_exception_ptr(__jniError)); + }); + return __promise; + }()); + }); + __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { + jni::JniException __jniError(__throwable); + __promise->reject(std::make_exception_ptr(__jniError)); + }); + return __promise; + }(); + } + }; + + /** + * An implementation of Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function>>>>()>& func) { - return JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____::newObjectCxxArgs(func); + return JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx::newObjectCxxArgs(func); } public: - jni::local_ref call() { + /** + * Invokes the C++ `std::function<...>` this `JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx` instance holds. + */ + jni::local_ref invoke_cxx() { std::shared_ptr>>>> __result = _func(); return [&]() { jni::local_ref __localPromise = JPromise::create(); @@ -60,18 +103,19 @@ namespace margelo::nitro::image { } public: + [[nodiscard]] inline const std::function>>>>()>& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx::invoke_cxx)}); } private: - explicit JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____(const std::function>>>>()>& func): _func(func) { } + explicit JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx(const std::function>>>>()>& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__string__.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__string__.hpp index bfde03c7a..17ef27bfb 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__string__.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__string__.hpp @@ -20,17 +20,49 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_std__shared_ptr_Promise_std__string__. - * This is a Kotlin `() -> Promise`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `() -> Promise`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_std__shared_ptr_Promise_std__string__ final: public jni::HybridClass { + struct JFunc_std__shared_ptr_Promise_std__string__: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__string__;"; + + public: + /** + * Invokes the function this `JFunc_std__shared_ptr_Promise_std__string__` instance holds through JNI. + */ + std::shared_ptr> invoke() const { + static const auto method = getClass()->getMethod()>("invoke"); + auto __result = method(self()); + return [&]() { + auto __promise = Promise::create(); + __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { + auto __result = jni::static_ref_cast(__boxedResult); + __promise->resolve(__result->toStdString()); + }); + __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { + jni::JniException __jniError(__throwable); + __promise->reject(std::make_exception_ptr(__jniError)); + }); + return __promise; + }(); + } + }; + + /** + * An implementation of Func_std__shared_ptr_Promise_std__string__ that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_std__shared_ptr_Promise_std__string___cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function>()>& func) { - return JFunc_std__shared_ptr_Promise_std__string__::newObjectCxxArgs(func); + return JFunc_std__shared_ptr_Promise_std__string___cxx::newObjectCxxArgs(func); } public: - jni::local_ref call() { + /** + * Invokes the C++ `std::function<...>` this `JFunc_std__shared_ptr_Promise_std__string___cxx` instance holds. + */ + jni::local_ref invoke_cxx() { std::shared_ptr> __result = _func(); return [&]() { jni::local_ref __localPromise = JPromise::create(); @@ -47,18 +79,19 @@ namespace margelo::nitro::image { } public: + [[nodiscard]] inline const std::function>()>& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__string__;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_std__shared_ptr_Promise_std__string___cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_std__shared_ptr_Promise_std__string__::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_std__shared_ptr_Promise_std__string___cxx::invoke_cxx)}); } private: - explicit JFunc_std__shared_ptr_Promise_std__string__(const std::function>()>& func): _func(func) { } + explicit JFunc_std__shared_ptr_Promise_std__string___cxx(const std::function>()>& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void.hpp index 5303f96f2..68b0a7512 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void.hpp @@ -17,33 +17,54 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_void. - * This is a Kotlin `() -> Unit`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `() -> Unit`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_void final: public jni::HybridClass { + struct JFunc_void: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void;"; + + public: + /** + * Invokes the function this `JFunc_void` instance holds through JNI. + */ + void invoke() const { + static const auto method = getClass()->getMethod("invoke"); + method(self()); + } + }; + + /** + * An implementation of Func_void that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_void_cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function& func) { - return JFunc_void::newObjectCxxArgs(func); + return JFunc_void_cxx::newObjectCxxArgs(func); } public: - void call() { + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_cxx` instance holds. + */ + void invoke_cxx() { _func(); } public: + [[nodiscard]] inline const std::function& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_void::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_void_cxx::invoke_cxx)}); } private: - explicit JFunc_void(const std::function& func): _func(func) { } + explicit JFunc_void_cxx(const std::function& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_double.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_double.hpp index 1567a6284..6cd66ede7 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_double.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_double.hpp @@ -17,33 +17,54 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_void_double. - * This is a Kotlin `(num: Double) -> Unit`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `(num: Double) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_void_double final: public jni::HybridClass { + struct JFunc_void_double: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_double;"; + + public: + /** + * Invokes the function this `JFunc_void_double` instance holds through JNI. + */ + void invoke(double num) const { + static const auto method = getClass()->getMethod("invoke"); + method(self(), num); + } + }; + + /** + * An implementation of Func_void_double that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_void_double_cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function& func) { - return JFunc_void_double::newObjectCxxArgs(func); + return JFunc_void_double_cxx::newObjectCxxArgs(func); } public: - void call(double num) { + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_double_cxx` instance holds. + */ + void invoke_cxx(double num) { _func(num); } public: + [[nodiscard]] inline const std::function& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_double;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_double_cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_void_double::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_void_double_cxx::invoke_cxx)}); } private: - explicit JFunc_void_double(const std::function& func): _func(func) { } + explicit JFunc_void_double_cxx(const std::function& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__optional_double_.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__optional_double_.hpp index 86d919c35..29b640679 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__optional_double_.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__optional_double_.hpp @@ -18,33 +18,54 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_void_std__optional_double_. - * This is a Kotlin `(maybe: Double?) -> Unit`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `(maybe: Double?) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_void_std__optional_double_ final: public jni::HybridClass { + struct JFunc_void_std__optional_double_: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__optional_double_;"; + + public: + /** + * Invokes the function this `JFunc_void_std__optional_double_` instance holds through JNI. + */ + void invoke(std::optional maybe) const { + static const auto method = getClass()->getMethod /* maybe */)>("invoke"); + method(self(), maybe.has_value() ? jni::JDouble::valueOf(maybe.value()) : nullptr); + } + }; + + /** + * An implementation of Func_void_std__optional_double_ that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_void_std__optional_double__cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function /* maybe */)>& func) { - return JFunc_void_std__optional_double_::newObjectCxxArgs(func); + return JFunc_void_std__optional_double__cxx::newObjectCxxArgs(func); } public: - void call(jni::alias_ref maybe) { + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_std__optional_double__cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref maybe) { _func(maybe != nullptr ? std::make_optional(maybe->value()) : std::nullopt); } public: + [[nodiscard]] inline const std::function /* maybe */)>& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__optional_double_;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__optional_double__cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_void_std__optional_double_::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_void_std__optional_double__cxx::invoke_cxx)}); } private: - explicit JFunc_void_std__optional_double_(const std::function /* maybe */)>& func): _func(func) { } + explicit JFunc_void_std__optional_double__cxx(const std::function /* maybe */)>& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__string.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__string.hpp index 74ba49b31..5bf6f155e 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__string.hpp @@ -18,33 +18,54 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_void_std__string. - * This is a Kotlin `(valueFromJs: String) -> Unit`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `(valueFromJs: String) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_void_std__string final: public jni::HybridClass { + struct JFunc_void_std__string: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__string;"; + + public: + /** + * Invokes the function this `JFunc_void_std__string` instance holds through JNI. + */ + void invoke(const std::string& valueFromJs) const { + static const auto method = getClass()->getMethod /* valueFromJs */)>("invoke"); + method(self(), jni::make_jstring(valueFromJs)); + } + }; + + /** + * An implementation of Func_void_std__string that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_void_std__string_cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function& func) { - return JFunc_void_std__string::newObjectCxxArgs(func); + return JFunc_void_std__string_cxx::newObjectCxxArgs(func); } public: - void call(jni::alias_ref valueFromJs) { + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_std__string_cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref valueFromJs) { _func(valueFromJs->toStdString()); } public: + [[nodiscard]] inline const std::function& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__string;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__string_cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_void_std__string::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_void_std__string_cxx::invoke_cxx)}); } private: - explicit JFunc_void_std__string(const std::function& func): _func(func) { } + explicit JFunc_void_std__string_cxx(const std::function& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__vector_Powertrain_.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__vector_Powertrain_.hpp index 289ccbc9b..ed06ecd0e 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__vector_Powertrain_.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_std__vector_Powertrain_.hpp @@ -20,17 +20,45 @@ namespace margelo::nitro::image { using namespace facebook; /** - * C++ representation of the callback Func_void_std__vector_Powertrain_. - * This is a Kotlin `(array: Array) -> Unit`, backed by a `std::function<...>`. + * Represents the Java/Kotlin callback `(array: Array) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. */ - struct JFunc_void_std__vector_Powertrain_ final: public jni::HybridClass { + struct JFunc_void_std__vector_Powertrain_: public jni::JavaClass { + public: + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__vector_Powertrain_;"; + + public: + /** + * Invokes the function this `JFunc_void_std__vector_Powertrain_` instance holds through JNI. + */ + void invoke(const std::vector& array) const { + static const auto method = getClass()->getMethod> /* array */)>("invoke"); + method(self(), [&]() { + size_t __size = array.size(); + jni::local_ref> __array = jni::JArrayClass::newArray(__size); + for (size_t __i = 0; __i < __size; __i++) { + const auto& __element = array[__i]; + __array->setElement(__i, *JPowertrain::fromCpp(__element)); + } + return __array; + }()); + } + }; + + /** + * An implementation of Func_void_std__vector_Powertrain_ that is backed by a C++ implementation (using `std::function<...>`) + */ + struct JFunc_void_std__vector_Powertrain__cxx final: public jni::HybridClass { public: static jni::local_ref fromCpp(const std::function& /* array */)>& func) { - return JFunc_void_std__vector_Powertrain_::newObjectCxxArgs(func); + return JFunc_void_std__vector_Powertrain__cxx::newObjectCxxArgs(func); } public: - void call(jni::alias_ref> array) { + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_Powertrain__cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref> array) { _func([&]() { size_t __size = array->size(); std::vector __vector; @@ -44,18 +72,19 @@ namespace margelo::nitro::image { } public: + [[nodiscard]] inline const std::function& /* array */)>& getFunction() const { return _func; } public: - static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__vector_Powertrain_;"; + static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_std__vector_Powertrain__cxx;"; static void registerNatives() { - registerHybrid({makeNativeMethod("call", JFunc_void_std__vector_Powertrain_::call)}); + registerHybrid({makeNativeMethod("invoke", JFunc_void_std__vector_Powertrain__cxx::invoke_cxx)}); } private: - explicit JFunc_void_std__vector_Powertrain_(const std::function& /* array */)>& func): _func(func) { } + explicit JFunc_void_std__vector_Powertrain__cxx(const std::function& /* array */)>& func): _func(func) { } private: friend HybridBase; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridImageSpec.cpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridImageSpec.cpp index d798a4a92..72d8827f4 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridImageSpec.cpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JHybridImageSpec.cpp @@ -69,8 +69,8 @@ namespace margelo::nitro::image { return __result; } void JHybridImageSpec::saveToFile(const std::string& path, const std::function& onFinished) { - static const auto method = _javaPart->getClass()->getMethod /* path */, jni::alias_ref /* onFinished */)>("saveToFile"); - method(_javaPart, jni::make_jstring(path), JFunc_void_std__string::fromCpp(onFinished)); + static const auto method = _javaPart->getClass()->getMethod /* path */, jni::alias_ref /* onFinished */)>("saveToFile_cxx"); + method(_javaPart, jni::make_jstring(path), JFunc_void_std__string_cxx::fromCpp(onFinished)); } } // namespace margelo::nitro::image 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 f8cbc0e77..89b325faa 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 @@ -39,6 +39,8 @@ namespace margelo::nitro::image { struct JsStyleStruct; } #include "JPowertrain.hpp" #include "OldEnum.hpp" #include "JOldEnum.hpp" +#include +#include "JFunc_void_double.hpp" #include #include "JVariant_String_Double.hpp" #include "Person.hpp" @@ -56,7 +58,6 @@ namespace margelo::nitro::image { struct JsStyleStruct; } #include "JHybridChildSpec.hpp" #include "HybridBaseSpec.hpp" #include "JHybridBaseSpec.hpp" -#include #include "JFunc_void_std__vector_Powertrain_.hpp" #include #include "JFunc_void.hpp" @@ -68,7 +69,6 @@ namespace margelo::nitro::image { struct JsStyleStruct; } #include "JFunc_void_std__string.hpp" #include "JsStyleStruct.hpp" #include "JJsStyleStruct.hpp" -#include "JFunc_void_double.hpp" namespace margelo::nitro::image { @@ -209,6 +209,24 @@ namespace margelo::nitro::image { static const auto method = _javaPart->getClass()->getMethod /* optionalOldEnum */)>("setOptionalOldEnum"); method(_javaPart, optionalOldEnum.has_value() ? JOldEnum::fromCpp(optionalOldEnum.value()) : nullptr); } + std::optional> JHybridTestObjectSwiftKotlinSpec::getOptionalCallback() { + static const auto method = _javaPart->getClass()->getMethod()>("getOptionalCallback_cxx"); + auto __result = method(_javaPart); + return __result != nullptr ? std::make_optional([&]() -> std::function { + if (__result->isInstanceOf(JFunc_void_double_cxx::javaClassStatic())) [[likely]] { + auto downcast = jni::static_ref_cast(__result); + return downcast->cthis()->getFunction(); + } else { + return [__result](double value) -> void { + return __result->invoke(value); + }; + } + }()) : std::nullopt; + } + void JHybridTestObjectSwiftKotlinSpec::setOptionalCallback(const std::optional>& optionalCallback) { + static const auto method = _javaPart->getClass()->getMethod /* optionalCallback */)>("setOptionalCallback_cxx"); + method(_javaPart, optionalCallback.has_value() ? JFunc_void_double_cxx::fromCpp(optionalCallback.value()) : nullptr); + } std::variant JHybridTestObjectSwiftKotlinSpec::getSomeVariant() { static const auto method = _javaPart->getClass()->getMethod()>("getSomeVariant"); auto __result = method(_javaPart); @@ -325,7 +343,7 @@ namespace margelo::nitro::image { }(); } void JHybridTestObjectSwiftKotlinSpec::complexEnumCallback(const std::vector& array, const std::function& /* array */)>& callback) { - static const auto method = _javaPart->getClass()->getMethod> /* array */, jni::alias_ref /* callback */)>("complexEnumCallback"); + static const auto method = _javaPart->getClass()->getMethod> /* array */, jni::alias_ref /* callback */)>("complexEnumCallback_cxx"); method(_javaPart, [&]() { size_t __size = array.size(); jni::local_ref> __array = jni::JArrayClass::newArray(__size); @@ -334,7 +352,7 @@ namespace margelo::nitro::image { __array->setElement(__i, *JPowertrain::fromCpp(__element)); } return __array; - }(), JFunc_void_std__vector_Powertrain_::fromCpp(callback)); + }(), JFunc_void_std__vector_Powertrain__cxx::fromCpp(callback)); } std::shared_ptr JHybridTestObjectSwiftKotlinSpec::createMap() { static const auto method = _javaPart->getClass()->getMethod()>("createMap"); @@ -517,20 +535,20 @@ namespace margelo::nitro::image { }(); } void JHybridTestObjectSwiftKotlinSpec::callCallback(const std::function& callback) { - static const auto method = _javaPart->getClass()->getMethod /* callback */)>("callCallback"); - method(_javaPart, JFunc_void::fromCpp(callback)); + static const auto method = _javaPart->getClass()->getMethod /* callback */)>("callCallback_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(callback)); } void JHybridTestObjectSwiftKotlinSpec::callAll(const std::function& first, const std::function& second, const std::function& third) { - static const auto method = _javaPart->getClass()->getMethod /* first */, jni::alias_ref /* second */, jni::alias_ref /* third */)>("callAll"); - method(_javaPart, JFunc_void::fromCpp(first), JFunc_void::fromCpp(second), JFunc_void::fromCpp(third)); + static const auto method = _javaPart->getClass()->getMethod /* first */, jni::alias_ref /* second */, jni::alias_ref /* third */)>("callAll_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(first), JFunc_void_cxx::fromCpp(second), JFunc_void_cxx::fromCpp(third)); } void JHybridTestObjectSwiftKotlinSpec::callWithOptional(std::optional value, const std::function /* maybe */)>& callback) { - static const auto method = _javaPart->getClass()->getMethod /* value */, jni::alias_ref /* callback */)>("callWithOptional"); - method(_javaPart, value.has_value() ? jni::JDouble::valueOf(value.value()) : nullptr, JFunc_void_std__optional_double_::fromCpp(callback)); + static const auto method = _javaPart->getClass()->getMethod /* value */, jni::alias_ref /* callback */)>("callWithOptional_cxx"); + method(_javaPart, value.has_value() ? jni::JDouble::valueOf(value.value()) : nullptr, JFunc_void_std__optional_double__cxx::fromCpp(callback)); } std::shared_ptr> JHybridTestObjectSwiftKotlinSpec::callSumUpNTimes(const std::function>()>& callback, double n) { - static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */, double /* n */)>("callSumUpNTimes"); - auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_double__::fromCpp(callback), n); + static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */, double /* n */)>("callSumUpNTimes_cxx"); + auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_double___cxx::fromCpp(callback), n); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { @@ -545,8 +563,8 @@ namespace margelo::nitro::image { }(); } std::shared_ptr> JHybridTestObjectSwiftKotlinSpec::callbackAsyncPromise(const std::function>>>()>& callback) { - static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */)>("callbackAsyncPromise"); - auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double____::fromCpp(callback)); + static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */)>("callbackAsyncPromise_cxx"); + auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx::fromCpp(callback)); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { @@ -561,8 +579,8 @@ namespace margelo::nitro::image { }(); } std::shared_ptr>> JHybridTestObjectSwiftKotlinSpec::callbackAsyncPromiseBuffer(const std::function>>>>()>& callback) { - static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */)>("callbackAsyncPromiseBuffer"); - auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____::fromCpp(callback)); + static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */)>("callbackAsyncPromiseBuffer_cxx"); + auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx::fromCpp(callback)); return [&]() { auto __promise = Promise>::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { @@ -576,9 +594,23 @@ namespace margelo::nitro::image { return __promise; }(); } + std::function JHybridTestObjectSwiftKotlinSpec::getComplexCallback() { + static const auto method = _javaPart->getClass()->getMethod()>("getComplexCallback_cxx"); + auto __result = method(_javaPart); + return [&]() -> std::function { + if (__result->isInstanceOf(JFunc_void_double_cxx::javaClassStatic())) [[likely]] { + auto downcast = jni::static_ref_cast(__result); + return downcast->cthis()->getFunction(); + } else { + return [__result](double value) -> void { + return __result->invoke(value); + }; + } + }(); + } std::shared_ptr> JHybridTestObjectSwiftKotlinSpec::getValueFromJSCallbackAndWait(const std::function>()>& getValue) { - static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* getValue */)>("getValueFromJSCallbackAndWait"); - auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_double__::fromCpp(getValue)); + static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* getValue */)>("getValueFromJSCallbackAndWait_cxx"); + auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_double___cxx::fromCpp(getValue)); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { @@ -593,8 +625,8 @@ namespace margelo::nitro::image { }(); } std::shared_ptr> JHybridTestObjectSwiftKotlinSpec::getValueFromJsCallback(const std::function>()>& callback, const std::function& andThenCall) { - static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */, jni::alias_ref /* andThenCall */)>("getValueFromJsCallback"); - auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_std__string__::fromCpp(callback), JFunc_void_std__string::fromCpp(andThenCall)); + static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* callback */, jni::alias_ref /* andThenCall */)>("getValueFromJsCallback_cxx"); + auto __result = method(_javaPart, JFunc_std__shared_ptr_Promise_std__string___cxx::fromCpp(callback), JFunc_void_std__string_cxx::fromCpp(andThenCall)); return [&]() { auto __promise = Promise::create(); __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& /* unit */) { @@ -623,7 +655,7 @@ namespace margelo::nitro::image { return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt; } void JHybridTestObjectSwiftKotlinSpec::jsStyleObjectAsParameters(const JsStyleStruct& params) { - static const auto method = _javaPart->getClass()->getMethod /* params */)>("jsStyleObjectAsParameters"); + static const auto method = _javaPart->getClass()->getMethod /* params */)>("jsStyleObjectAsParameters_cxx"); method(_javaPart, JJsStyleStruct::fromCpp(params)); } std::shared_ptr JHybridTestObjectSwiftKotlinSpec::createArrayBuffer() { 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 980526786..161a15dff 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 @@ -70,6 +70,8 @@ namespace margelo::nitro::image { void setOptionalEnum(std::optional optionalEnum) override; std::optional getOptionalOldEnum() override; void setOptionalOldEnum(std::optional optionalOldEnum) override; + std::optional> getOptionalCallback() override; + void setOptionalCallback(const std::optional>& optionalCallback) override; std::variant getSomeVariant() override; void setSomeVariant(const std::variant& someVariant) override; @@ -106,6 +108,7 @@ namespace margelo::nitro::image { std::shared_ptr> callSumUpNTimes(const std::function>()>& callback, double n) override; std::shared_ptr> callbackAsyncPromise(const std::function>>>()>& callback) override; std::shared_ptr>> callbackAsyncPromiseBuffer(const std::function>>>>()>& callback) override; + std::function getComplexCallback() override; std::shared_ptr> getValueFromJSCallbackAndWait(const std::function>()>& getValue) override; std::shared_ptr> getValueFromJsCallback(const std::function>()>& callback, const std::function& andThenCall) override; Car getCar() override; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageFormat.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageFormat.hpp index 38aa6806d..9d7e973f8 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageFormat.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageFormat.hpp @@ -26,6 +26,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based enum to the C++ enum ImageFormat. */ [[maybe_unused]] + [[nodiscard]] ImageFormat toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldOrdinal = clazz->getField("_ordinal"); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageSize.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageSize.hpp index bb0c071b5..49ce88f67 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageSize.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JImageSize.hpp @@ -28,6 +28,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based struct to the C++ struct ImageSize by copying all values to C++. */ [[maybe_unused]] + [[nodiscard]] ImageSize toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldWidth = clazz->getField("width"); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JJsStyleStruct.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JJsStyleStruct.hpp index 7ba72a918..9007975a6 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JJsStyleStruct.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JJsStyleStruct.hpp @@ -29,6 +29,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based struct to the C++ struct JsStyleStruct by copying all values to C++. */ [[maybe_unused]] + [[nodiscard]] JsStyleStruct toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldValue = clazz->getField("value"); @@ -37,7 +38,16 @@ namespace margelo::nitro::image { jni::local_ref onChanged = this->getFieldValue(fieldOnChanged); return JsStyleStruct( value, - onChanged->cthis()->getFunction() + [&]() -> std::function { + if (onChanged->isInstanceOf(JFunc_void_double_cxx::javaClassStatic())) [[likely]] { + auto downcast = jni::static_ref_cast(onChanged); + return downcast->cthis()->getFunction(); + } else { + return [onChanged](double num) -> void { + return onChanged->invoke(num); + }; + } + }() ); } @@ -49,7 +59,7 @@ namespace margelo::nitro::image { static jni::local_ref fromCpp(const JsStyleStruct& value) { return newInstance( value.value, - JFunc_void_double::fromCpp(value.onChanged) + JFunc_void_double_cxx::fromCpp(value.onChanged) ); } }; diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JOldEnum.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JOldEnum.hpp index 06952445d..97d62ebba 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JOldEnum.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JOldEnum.hpp @@ -26,6 +26,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based enum to the C++ enum OldEnum. */ [[maybe_unused]] + [[nodiscard]] OldEnum toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldOrdinal = clazz->getField("_ordinal"); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPerson.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPerson.hpp index 0959d1647..c30b0a291 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPerson.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPerson.hpp @@ -28,6 +28,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based struct to the C++ struct Person by copying all values to C++. */ [[maybe_unused]] + [[nodiscard]] Person toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldName = clazz->getField("name"); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPixelFormat.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPixelFormat.hpp index cfb0727dc..d9f7e2a13 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPixelFormat.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPixelFormat.hpp @@ -26,6 +26,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based enum to the C++ enum PixelFormat. */ [[maybe_unused]] + [[nodiscard]] PixelFormat toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldOrdinal = clazz->getField("_ordinal"); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPowertrain.hpp b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPowertrain.hpp index 31567f3b5..b150b829c 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPowertrain.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/android/c++/JPowertrain.hpp @@ -26,6 +26,7 @@ namespace margelo::nitro::image { * Convert this Java/Kotlin-based enum to the C++ enum Powertrain. */ [[maybe_unused]] + [[nodiscard]] Powertrain toCpp() const { static const auto clazz = javaClassStatic(); static const auto fieldOrdinal = clazz->getField("_ordinal"); diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Car.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Car.kt index e635a34f0..b5adf5281 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Car.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Car.kt @@ -16,12 +16,17 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -data class Car( - val year: Double, - val make: String, - val model: String, - val power: Double, - val powertrain: Powertrain, - val driver: Person?, - val isFast: Boolean? -) +data class Car + @DoNotStrip + @Keep + constructor( + val year: Double, + val make: String, + val model: String, + val power: Double, + val powertrain: Powertrain, + val driver: Person?, + val isFast: Boolean? + ) { + /* main constructor */ +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_double__.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_double__.kt index 417ebb17c..df857a61b 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_double__.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_double__.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `() => std::shared_ptr>`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_std__shared_ptr_Promise_double__: () -> Promise { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(): Promise +} + /** * Represents the JavaScript callback `() => std::shared_ptr>`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_std__shared_ptr_Promise_double__ { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_std__shared_ptr_Promise_double___cxx: Func_std__shared_ptr_Promise_double__ { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_std__shared_ptr_Promise_double__ { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): () -> Promise = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(): Promise + external override fun invoke(): Promise +} + +/** + * Represents the JavaScript callback `() => std::shared_ptr>`. + * This is implemented in Java/Kotlin, via a `() -> Promise`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_std__shared_ptr_Promise_double___java(private val function: () -> Promise): Func_std__shared_ptr_Promise_double__ { + @DoNotStrip + @Keep + override fun invoke(): Promise { + return this.function() + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.kt index ef881424e..d607dab39 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `() => std::shared_ptr>>>`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____: () -> Promise> { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(): Promise> +} + /** * Represents the JavaScript callback `() => std::shared_ptr>>>`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____cxx: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): () -> Promise> = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(): Promise> + external override fun invoke(): Promise> +} + +/** + * Represents the JavaScript callback `() => std::shared_ptr>>>`. + * This is implemented in Java/Kotlin, via a `() -> Promise>`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____java(private val function: () -> Promise>): Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ { + @DoNotStrip + @Keep + override fun invoke(): Promise> { + return this.function() + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.kt index aca285408..a4f6bb72d 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `() => std::shared_ptr>>>>`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____: () -> Promise> { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(): Promise> +} + /** * Represents the JavaScript callback `() => std::shared_ptr>>>>`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______cxx: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_Array mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): () -> Promise> = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(): Promise> + external override fun invoke(): Promise> +} + +/** + * Represents the JavaScript callback `() => std::shared_ptr>>>>`. + * This is implemented in Java/Kotlin, via a `() -> Promise>`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer______java(private val function: () -> Promise>): Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ { + @DoNotStrip + @Keep + override fun invoke(): Promise> { + return this.function() + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__string__.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__string__.kt index 25acb75d1..d9b5b9415 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__string__.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_std__shared_ptr_Promise_std__string__.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `() => std::shared_ptr>`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_std__shared_ptr_Promise_std__string__: () -> Promise { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(): Promise +} + /** * Represents the JavaScript callback `() => std::shared_ptr>`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_std__shared_ptr_Promise_std__string__ { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_std__shared_ptr_Promise_std__string___cxx: Func_std__shared_ptr_Promise_std__string__ { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_std__shared_ptr_Promise_std__string__ { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): () -> Promise = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(): Promise + external override fun invoke(): Promise +} + +/** + * Represents the JavaScript callback `() => std::shared_ptr>`. + * This is implemented in Java/Kotlin, via a `() -> Promise`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_std__shared_ptr_Promise_std__string___java(private val function: () -> Promise): Func_std__shared_ptr_Promise_std__string__ { + @DoNotStrip + @Keep + override fun invoke(): Promise { + return this.function() + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void.kt index f2a219379..81142b3c6 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `() => void`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_void: () -> Unit { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(): Unit +} + /** * Represents the JavaScript callback `() => void`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_void { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_void_cxx: Func_void { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_void { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): () -> Unit = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(): Unit + external override fun invoke(): Unit +} + +/** + * Represents the JavaScript callback `() => void`. + * This is implemented in Java/Kotlin, via a `() -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_java(private val function: () -> Unit): Func_void { + @DoNotStrip + @Keep + override fun invoke(): Unit { + return this.function() + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_double.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_double.kt index 382498e13..1670876c9 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_double.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_double.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `(num: number) => void`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_void_double: (Double) -> Unit { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(num: Double): Unit +} + /** * Represents the JavaScript callback `(num: number) => void`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_void_double { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_void_double_cxx: Func_void_double { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_void_double { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): (num: Double) -> Unit = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(num: Double): Unit + external override fun invoke(num: Double): Unit +} + +/** + * Represents the JavaScript callback `(num: number) => void`. + * This is implemented in Java/Kotlin, via a `(Double) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_double_java(private val function: (Double) -> Unit): Func_void_double { + @DoNotStrip + @Keep + override fun invoke(num: Double): Unit { + return this.function(num) + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__optional_double_.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__optional_double_.kt index 1968b4eac..960800ae5 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__optional_double_.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__optional_double_.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `(maybe: optional) => void`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_void_std__optional_double_: (Double?) -> Unit { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(maybe: Double?): Unit +} + /** * Represents the JavaScript callback `(maybe: optional) => void`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_void_std__optional_double_ { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_void_std__optional_double__cxx: Func_void_std__optional_double_ { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_void_std__optional_double_ { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): (maybe: Double?) -> Unit = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(maybe: Double?): Unit + external override fun invoke(maybe: Double?): Unit +} + +/** + * Represents the JavaScript callback `(maybe: optional) => void`. + * This is implemented in Java/Kotlin, via a `(Double?) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_std__optional_double__java(private val function: (Double?) -> Unit): Func_void_std__optional_double_ { + @DoNotStrip + @Keep + override fun invoke(maybe: Double?): Unit { + return this.function(maybe) + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__string.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__string.kt index 2971e85c0..f1e304121 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__string.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__string.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `(valueFromJs: string) => void`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_void_std__string: (String) -> Unit { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(valueFromJs: String): Unit +} + /** * Represents the JavaScript callback `(valueFromJs: string) => void`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_void_std__string { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_void_std__string_cxx: Func_void_std__string { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_void_std__string { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): (valueFromJs: String) -> Unit = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(valueFromJs: String): Unit + external override fun invoke(valueFromJs: String): Unit +} + +/** + * Represents the JavaScript callback `(valueFromJs: string) => void`. + * This is implemented in Java/Kotlin, via a `(String) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_std__string_java(private val function: (String) -> Unit): Func_void_std__string { + @DoNotStrip + @Keep + override fun invoke(valueFromJs: String): Unit { + return this.function(valueFromJs) + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__vector_Powertrain_.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__vector_Powertrain_.kt index 13a00d152..01e439a7d 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__vector_Powertrain_.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Func_void_std__vector_Powertrain_.kt @@ -13,14 +13,37 @@ import com.facebook.proguard.annotations.DoNotStrip import com.margelo.nitro.core.* import dalvik.annotation.optimization.FastNative +/** + * Represents the JavaScript callback `(array: array) => void`. + * This can be either implemented in C++ (in which case it might be a callback coming from JS), + * or in Kotlin/Java (in which case it is a native callback). + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType") +fun interface Func_void_std__vector_Powertrain_: (Array) -> Unit { + /** + * Call the given JS callback. + * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. + */ + @DoNotStrip + @Keep + override fun invoke(array: Array): Unit +} + /** * Represents the JavaScript callback `(array: array) => void`. * This is implemented in C++, via a `std::function<...>`. + * The callback might be coming from JS. */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") -class Func_void_std__vector_Powertrain_ { +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", + "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName", +) +class Func_void_std__vector_Powertrain__cxx: Func_void_std__vector_Powertrain_ { @DoNotStrip @Keep private val mHybridData: HybridData @@ -31,16 +54,22 @@ class Func_void_std__vector_Powertrain_ { mHybridData = hybridData } - /** - * Converts this function to a Kotlin Lambda. - * This exists purely as syntactic sugar, and has minimal runtime overhead. - */ - fun toLambda(): (array: Array) -> Unit = this::call - - /** - * Call the given JS callback. - * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. - */ @FastNative - external fun call(array: Array): Unit + external override fun invoke(array: Array): Unit +} + +/** + * Represents the JavaScript callback `(array: array) => void`. + * This is implemented in Java/Kotlin, via a `(Array) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_std__vector_Powertrain__java(private val function: (Array) -> Unit): Func_void_std__vector_Powertrain_ { + @DoNotStrip + @Keep + override fun invoke(array: Array): Unit { + return this.function(array) + } } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridBaseSpec.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridBaseSpec.kt index ce5d21699..15cf9bd72 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridBaseSpec.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridBaseSpec.kt @@ -19,7 +19,11 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) abstract class HybridBaseSpec: HybridObject() { @DoNotStrip private var mHybridData: HybridData = initHybrid() diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridChildSpec.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridChildSpec.kt index 184f6a2dd..ee68eeac3 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridChildSpec.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridChildSpec.kt @@ -19,7 +19,11 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) abstract class HybridChildSpec: HybridBaseSpec() { @DoNotStrip private var mHybridData: HybridData = initHybrid() diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageFactorySpec.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageFactorySpec.kt index d91ca6847..89135dae1 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageFactorySpec.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageFactorySpec.kt @@ -19,7 +19,11 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) abstract class HybridImageFactorySpec: HybridObject() { @DoNotStrip private var mHybridData: HybridData = initHybrid() diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageSpec.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageSpec.kt index dd3fd10b2..f4b7013e9 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageSpec.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/HybridImageSpec.kt @@ -19,7 +19,11 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) abstract class HybridImageSpec: HybridObject() { @DoNotStrip private var mHybridData: HybridData = initHybrid() @@ -57,14 +61,12 @@ abstract class HybridImageSpec: HybridObject() { @Keep abstract fun toArrayBuffer(format: ImageFormat): Double - @DoNotStrip - @Keep abstract fun saveToFile(path: String, onFinished: (path: String) -> Unit): Unit @DoNotStrip @Keep - private fun saveToFile(path: String, onFinished: Func_void_std__string): Unit { - val __result = saveToFile(path, onFinished.toLambda()) + private fun saveToFile_cxx(path: String, onFinished: Func_void_std__string): Unit { + val __result = saveToFile(path, onFinished) return __result } 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 39accdc1e..8f1bd0b40 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 @@ -19,7 +19,11 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() { @DoNotStrip private var mHybridData: HybridData = initHybrid() @@ -108,6 +112,20 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() { @set:Keep abstract var optionalOldEnum: OldEnum? + abstract var optionalCallback: ((value: Double) -> Unit)? + + private var optionalCallback_cxx: Func_void_double? + @Keep + @DoNotStrip + get() { + return optionalCallback?.let { Func_void_double_java(it) } + } + @Keep + @DoNotStrip + set(value) { + optionalCallback = value?.let { it } + } + @get:DoNotStrip @get:Keep @set:DoNotStrip @@ -151,14 +169,12 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() { @Keep abstract fun bounceEnums(array: Array): Array - @DoNotStrip - @Keep abstract fun complexEnumCallback(array: Array, callback: (array: Array) -> Unit): Unit @DoNotStrip @Keep - private fun complexEnumCallback(array: Array, callback: Func_void_std__vector_Powertrain_): Unit { - val __result = complexEnumCallback(array, callback.toLambda()) + private fun complexEnumCallback_cxx(array: Array, callback: Func_void_std__vector_Powertrain_): Unit { + val __result = complexEnumCallback(array, callback) return __result } @@ -222,91 +238,84 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() { @Keep abstract fun awaitPromise(promise: Promise): Promise - @DoNotStrip - @Keep abstract fun callCallback(callback: () -> Unit): Unit @DoNotStrip @Keep - private fun callCallback(callback: Func_void): Unit { - val __result = callCallback(callback.toLambda()) + private fun callCallback_cxx(callback: Func_void): Unit { + val __result = callCallback(callback) return __result } - @DoNotStrip - @Keep abstract fun callAll(first: () -> Unit, second: () -> Unit, third: () -> Unit): Unit @DoNotStrip @Keep - private fun callAll(first: Func_void, second: Func_void, third: Func_void): Unit { - val __result = callAll(first.toLambda(), second.toLambda(), third.toLambda()) + private fun callAll_cxx(first: Func_void, second: Func_void, third: Func_void): Unit { + val __result = callAll(first, second, third) return __result } - @DoNotStrip - @Keep abstract fun callWithOptional(value: Double?, callback: (maybe: Double?) -> Unit): Unit @DoNotStrip @Keep - private fun callWithOptional(value: Double?, callback: Func_void_std__optional_double_): Unit { - val __result = callWithOptional(value, callback.toLambda()) + private fun callWithOptional_cxx(value: Double?, callback: Func_void_std__optional_double_): Unit { + val __result = callWithOptional(value, callback) return __result } - @DoNotStrip - @Keep abstract fun callSumUpNTimes(callback: () -> Promise, n: Double): Promise @DoNotStrip @Keep - private fun callSumUpNTimes(callback: Func_std__shared_ptr_Promise_double__, n: Double): Promise { - val __result = callSumUpNTimes(callback.toLambda(), n) + private fun callSumUpNTimes_cxx(callback: Func_std__shared_ptr_Promise_double__, n: Double): Promise { + val __result = callSumUpNTimes(callback, n) return __result } - @DoNotStrip - @Keep abstract fun callbackAsyncPromise(callback: () -> Promise>): Promise @DoNotStrip @Keep - private fun callbackAsyncPromise(callback: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____): Promise { - val __result = callbackAsyncPromise(callback.toLambda()) + private fun callbackAsyncPromise_cxx(callback: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____): Promise { + val __result = callbackAsyncPromise(callback) return __result } - @DoNotStrip - @Keep abstract fun callbackAsyncPromiseBuffer(callback: () -> Promise>): Promise @DoNotStrip @Keep - private fun callbackAsyncPromiseBuffer(callback: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____): Promise { - val __result = callbackAsyncPromiseBuffer(callback.toLambda()) + private fun callbackAsyncPromiseBuffer_cxx(callback: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____): Promise { + val __result = callbackAsyncPromiseBuffer(callback) return __result } + abstract fun getComplexCallback(): (value: Double) -> Unit + @DoNotStrip @Keep + private fun getComplexCallback_cxx(): Func_void_double { + val __result = getComplexCallback() + return Func_void_double_java(__result) + } + abstract fun getValueFromJSCallbackAndWait(getValue: () -> Promise): Promise @DoNotStrip @Keep - private fun getValueFromJSCallbackAndWait(getValue: Func_std__shared_ptr_Promise_double__): Promise { - val __result = getValueFromJSCallbackAndWait(getValue.toLambda()) + private fun getValueFromJSCallbackAndWait_cxx(getValue: Func_std__shared_ptr_Promise_double__): Promise { + val __result = getValueFromJSCallbackAndWait(getValue) return __result } - @DoNotStrip - @Keep abstract fun getValueFromJsCallback(callback: () -> Promise, andThenCall: (valueFromJs: String) -> Unit): Promise @DoNotStrip @Keep - private fun getValueFromJsCallback(callback: Func_std__shared_ptr_Promise_std__string__, andThenCall: Func_void_std__string): Promise { - val __result = getValueFromJsCallback(callback.toLambda(), andThenCall.toLambda()) + private fun getValueFromJsCallback_cxx(callback: Func_std__shared_ptr_Promise_std__string__, andThenCall: Func_void_std__string): Promise { + val __result = getValueFromJsCallback(callback, andThenCall) return __result } @@ -322,9 +331,14 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() { @Keep abstract fun getDriver(car: Car): Person? + abstract fun jsStyleObjectAsParameters(params: JsStyleStruct): Unit + @DoNotStrip @Keep - abstract fun jsStyleObjectAsParameters(params: JsStyleStruct): Unit + private fun jsStyleObjectAsParameters_cxx(params: JsStyleStruct): Unit { + val __result = jsStyleObjectAsParameters(params) + return __result + } @DoNotStrip @Keep diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/ImageSize.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/ImageSize.kt index c708c6a4d..2b70d2a91 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/ImageSize.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/ImageSize.kt @@ -16,7 +16,12 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -data class ImageSize( - val width: Double, - val height: Double -) +data class ImageSize + @DoNotStrip + @Keep + constructor( + val width: Double, + val height: Double + ) { + /* main constructor */ +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/JsStyleStruct.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/JsStyleStruct.kt index c6d6b4fb8..bda4f31d2 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/JsStyleStruct.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/JsStyleStruct.kt @@ -16,7 +16,16 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -data class JsStyleStruct( - val value: Double, - val onChanged: (num: Double) -> Unit -) +data class JsStyleStruct + @DoNotStrip + @Keep + constructor( + val value: Double, + val onChanged: (num: Double) -> Unit + ) { + @DoNotStrip + @Keep + @Suppress("unused") + private constructor(value: Double, onChanged: Func_void_double) + : this(value, onChanged as (num: Double) -> Unit) +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Person.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Person.kt index 45099f9ac..b475a751b 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Person.kt +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/Person.kt @@ -16,7 +16,12 @@ import com.margelo.nitro.core.* */ @DoNotStrip @Keep -data class Person( - val name: String, - val age: Double -) +data class Person + @DoNotStrip + @Keep + constructor( + val name: String, + val age: Double + ) { + /* main constructor */ +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp index 4dcca2c3d..f52d03c69 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp @@ -73,6 +73,14 @@ namespace margelo::nitro::image::bridge::swift { return swiftPart.toUnsafe(); } + // pragma MARK: std::function + Func_void_double create_Func_void_double(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_double::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](double value) mutable -> void { + swiftClosure.call(value); + }; + } + // pragma MARK: std::function& /* array */)> Func_void_std__vector_Powertrain_ create_Func_void_std__vector_Powertrain_(void* _Nonnull swiftClosureWrapper) { auto swiftClosure = NitroImage::Func_void_std__vector_Powertrain_::fromUnsafe(swiftClosureWrapper); @@ -105,14 +113,6 @@ namespace margelo::nitro::image::bridge::swift { }; } - // pragma MARK: std::function - Func_void_double create_Func_void_double(void* _Nonnull swiftClosureWrapper) { - auto swiftClosure = NitroImage::Func_void_double::fromUnsafe(swiftClosureWrapper); - return [swiftClosure = std::move(swiftClosure)](double result) mutable -> void { - swiftClosure.call(result); - }; - } - // pragma MARK: std::function Func_void_Car create_Func_void_Car(void* _Nonnull swiftClosureWrapper) { auto swiftClosure = NitroImage::Func_void_Car::fromUnsafe(swiftClosureWrapper); 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 a1309ade8..761a6b126 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 @@ -216,6 +216,37 @@ namespace margelo::nitro::image::bridge::swift { return std::optional(value); } + // pragma MARK: std::function + /** + * Specialized version of `std::function`. + */ + using Func_void_double = std::function; + /** + * Wrapper class for a `std::function`, this can be used from Swift. + */ + class Func_void_double_Wrapper final { + public: + explicit Func_void_double_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} + inline void call(double value) const { + _function->operator()(value); + } + private: + std::shared_ptr> _function; + }; + Func_void_double create_Func_void_double(void* _Nonnull swiftClosureWrapper); + inline Func_void_double_Wrapper wrap_Func_void_double(Func_void_double value) { + return Func_void_double_Wrapper(std::move(value)); + } + + // pragma MARK: std::optional> + /** + * Specialized version of `std::optional>`. + */ + using std__optional_std__function_void_double____value______ = std::optional>; + inline std::optional> create_std__optional_std__function_void_double____value______(const std::function& value) { + return std::optional>(value); + } + // pragma MARK: std::vector /** * Specialized version of `std::vector`. @@ -411,28 +442,6 @@ namespace margelo::nitro::image::bridge::swift { return PromiseHolder(std::move(promise)); } - // pragma MARK: std::function - /** - * Specialized version of `std::function`. - */ - using Func_void_double = std::function; - /** - * Wrapper class for a `std::function`, this can be used from Swift. - */ - class Func_void_double_Wrapper final { - public: - explicit Func_void_double_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} - inline void call(double result) const { - _function->operator()(result); - } - private: - std::shared_ptr> _function; - }; - Func_void_double create_Func_void_double(void* _Nonnull swiftClosureWrapper); - inline Func_void_double_Wrapper wrap_Func_void_double(Func_void_double value) { - return Func_void_double_Wrapper(std::move(value)); - } - // pragma MARK: std::optional /** * Specialized version of `std::optional`. @@ -866,6 +875,15 @@ namespace margelo::nitro::image::bridge::swift { return Result>>>::withError(error); } + // pragma MARK: Result> + using Result_std__function_void_double____value______ = Result>; + inline Result_std__function_void_double____value______ create_Result_std__function_void_double____value______(const std::function& value) { + return Result>::withValue(value); + } + inline Result_std__function_void_double____value______ create_Result_std__function_void_double____value______(const std::exception_ptr& error) { + return Result>::withError(error); + } + // pragma MARK: Result using Result_Car_ = Result; inline Result_Car_ create_Result_Car_(const Car& value) { 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 3b5372f7f..463fa5209 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 @@ -42,9 +42,9 @@ namespace margelo::nitro::image { class HybridBaseSpec; } #include #include "Powertrain.hpp" #include "OldEnum.hpp" +#include #include #include "Person.hpp" -#include #include #include #include @@ -166,6 +166,13 @@ namespace margelo::nitro::image { inline void setOptionalOldEnum(std::optional optionalOldEnum) noexcept override { _swiftPart.setOptionalOldEnum(optionalOldEnum); } + inline std::optional> getOptionalCallback() noexcept override { + auto __result = _swiftPart.getOptionalCallback(); + return __result; + } + inline void setOptionalCallback(const std::optional>& optionalCallback) noexcept override { + _swiftPart.setOptionalCallback(optionalCallback); + } inline std::variant getSomeVariant() noexcept override { auto __result = _swiftPart.getSomeVariant(); return __result; @@ -410,6 +417,14 @@ namespace margelo::nitro::image { auto __value = std::move(__result.value()); return __value; } + inline std::function getComplexCallback() override { + auto __result = _swiftPart.getComplexCallback(); + if (__result.hasError()) [[unlikely]] { + std::rethrow_exception(__result.error()); + } + auto __value = std::move(__result.value()); + return __value; + } inline std::shared_ptr> getValueFromJSCallbackAndWait(const std::function>()>& getValue) override { auto __result = _swiftPart.getValueFromJSCallbackAndWait(getValue); if (__result.hasError()) [[unlikely]] { diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_double__.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_double__.swift index 8cfd7ba22..240a49760 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_double__.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_double__.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `(() -> Promise)` as a class. + * Wraps a Swift `() -> Promise` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_std__shared_ptr_Promise_double__ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: (() -> Promise) + private let closure: () -> Promise - public init(_ closure: @escaping (() -> Promise)) { + public init(_ closure: @escaping () -> Promise) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.swift index 29cc37dc0..da5935d07 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `(() -> Promise>)` as a class. + * Wraps a Swift `() -> Promise>` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: (() -> Promise>) + private let closure: () -> Promise> - public init(_ closure: @escaping (() -> Promise>)) { + public init(_ closure: @escaping () -> Promise>) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.swift index 6d2fb6049..88c3c29e7 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `(() -> Promise>)` as a class. + * Wraps a Swift `() -> Promise>` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: (() -> Promise>) + private let closure: () -> Promise> - public init(_ closure: @escaping (() -> Promise>)) { + public init(_ closure: @escaping () -> Promise>) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__string__.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__string__.swift index fd80d87e7..5a0d9e783 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__string__.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__string__.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `(() -> Promise)` as a class. + * Wraps a Swift `() -> Promise` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_std__shared_ptr_Promise_std__string__ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: (() -> Promise) + private let closure: () -> Promise - public init(_ closure: @escaping (() -> Promise)) { + public init(_ closure: @escaping () -> Promise) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void.swift index 7fba8d487..0d9f0f000 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `(() -> Void)` as a class. + * Wraps a Swift `() -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: (() -> Void) + private let closure: () -> Void - public init(_ closure: @escaping (() -> Void)) { + public init(_ closure: @escaping () -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_Car.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_Car.swift index eca6c1a70..1c4c542ef 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_Car.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_Car.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ value: Car) -> Void)` as a class. + * Wraps a Swift `(_ value: Car) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_Car { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ value: Car) -> Void) + private let closure: (_ value: Car) -> Void - public init(_ closure: @escaping ((_ value: Car) -> Void)) { + public init(_ closure: @escaping (_ value: Car) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_double.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_double.swift index 4bf33cdff..279b77bbd 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_double.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_double.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ num: Double) -> Void)` as a class. + * Wraps a Swift `(_ num: Double) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_double { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ num: Double) -> Void) + private let closure: (_ num: Double) -> Void - public init(_ closure: @escaping ((_ num: Double) -> Void)) { + public init(_ closure: @escaping (_ num: Double) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_int64_t.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_int64_t.swift index 720779803..d05f254ed 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_int64_t.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_int64_t.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ value: Int64) -> Void)` as a class. + * Wraps a Swift `(_ value: Int64) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_int64_t { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ value: Int64) -> Void) + private let closure: (_ value: Int64) -> Void - public init(_ closure: @escaping ((_ value: Int64) -> Void)) { + public init(_ closure: @escaping (_ value: Int64) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift index becb5f9d0..bb3cd9b36 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ error: Error) -> Void)` as a class. + * Wraps a Swift `(_ error: Error) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_std__exception_ptr { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ error: Error) -> Void) + private let closure: (_ error: Error) -> Void - public init(_ closure: @escaping ((_ error: Error) -> Void)) { + public init(_ closure: @escaping (_ error: Error) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift index b2c12eada..986aa6dc2 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ maybe: Double?) -> Void)` as a class. + * Wraps a Swift `(_ maybe: Double?) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_std__optional_double_ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ maybe: Double?) -> Void) + private let closure: (_ maybe: Double?) -> Void - public init(_ closure: @escaping ((_ maybe: Double?) -> Void)) { + public init(_ closure: @escaping (_ maybe: Double?) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift index 39a06c803..0589d9e27 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ value: ArrayBufferHolder) -> Void)` as a class. + * Wraps a Swift `(_ value: ArrayBufferHolder) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_std__shared_ptr_ArrayBuffer_ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ value: ArrayBufferHolder) -> Void) + private let closure: (_ value: ArrayBufferHolder) -> Void - public init(_ closure: @escaping ((_ value: ArrayBufferHolder) -> Void)) { + public init(_ closure: @escaping (_ value: ArrayBufferHolder) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_double__.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_double__.swift index 6ef08bc2e..ead1ada94 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_double__.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_double__.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ value: Promise) -> Void)` as a class. + * Wraps a Swift `(_ value: Promise) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_std__shared_ptr_Promise_double__ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ value: Promise) -> Void) + private let closure: (_ value: Promise) -> Void - public init(_ closure: @escaping ((_ value: Promise) -> Void)) { + public init(_ closure: @escaping (_ value: Promise) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___.swift index 4418d5120..4de6e45f5 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ value: Promise) -> Void)` as a class. + * Wraps a Swift `(_ value: Promise) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ value: Promise) -> Void) + private let closure: (_ value: Promise) -> Void - public init(_ closure: @escaping ((_ value: Promise) -> Void)) { + public init(_ closure: @escaping (_ value: Promise) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__string.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__string.swift index c489a9c41..9cc6f2d7d 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__string.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__string.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ valueFromJs: String) -> Void)` as a class. + * Wraps a Swift `(_ valueFromJs: String) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_std__string { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ valueFromJs: String) -> Void) + private let closure: (_ valueFromJs: String) -> Void - public init(_ closure: @escaping ((_ valueFromJs: String) -> Void)) { + public init(_ closure: @escaping (_ valueFromJs: String) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__vector_Powertrain_.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__vector_Powertrain_.swift index 1498709ad..9948fcc08 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__vector_Powertrain_.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__vector_Powertrain_.swift @@ -8,15 +8,15 @@ import NitroModules /** - * Wraps a Swift `((_ array: [Powertrain]) -> Void)` as a class. + * Wraps a Swift `(_ array: [Powertrain]) -> Void` as a class. * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. */ public final class Func_void_std__vector_Powertrain_ { public typealias bridge = margelo.nitro.image.bridge.swift - private let closure: ((_ array: [Powertrain]) -> Void) + private let closure: (_ array: [Powertrain]) -> Void - public init(_ closure: @escaping ((_ array: [Powertrain]) -> Void)) { + public init(_ closure: @escaping (_ array: [Powertrain]) -> Void) { self.closure = closure } diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec.swift index 44d57792f..e02e5263a 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec.swift @@ -17,7 +17,7 @@ public protocol HybridImageSpec_protocol: AnyObject { // Methods func toArrayBuffer(format: ImageFormat) throws -> Double - func saveToFile(path: String, onFinished: @escaping ((_ path: String) -> Void)) throws -> Void + func saveToFile(path: String, onFinished: @escaping (_ path: String) -> Void) throws -> Void } /// See ``HybridImageSpec`` diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift index 202ab061d..fa5fab666 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift @@ -138,7 +138,7 @@ public class HybridImageSpec_cxx { @inline(__always) public func saveToFile(path: std.string, onFinished: bridge.Func_void_std__string) -> bridge.Result_void_ { do { - try self.__implementation.saveToFile(path: String(path), onFinished: { () -> ((String) -> Void) in + try self.__implementation.saveToFile(path: String(path), onFinished: { () -> (String) -> Void in let __wrappedFunction = bridge.wrap_Func_void_std__string(onFinished) return { (__path: String) -> Void in __wrappedFunction.call(std.string(__path)) 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 6bb5cdfa2..d9dff5631 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 @@ -23,6 +23,7 @@ public protocol HybridTestObjectSwiftKotlinSpec_protocol: AnyObject { var optionalArray: [String]? { get set } var optionalEnum: Powertrain? { get set } var optionalOldEnum: OldEnum? { get set } + var optionalCallback: ((_ value: Double) -> Void)? { get set } var someVariant: Variant_String_Double { get set } // Methods @@ -35,7 +36,7 @@ public protocol HybridTestObjectSwiftKotlinSpec_protocol: AnyObject { func bounceNumbers(array: [Double]) throws -> [Double] func bounceStructs(array: [Person]) throws -> [Person] func bounceEnums(array: [Powertrain]) throws -> [Powertrain] - func complexEnumCallback(array: [Powertrain], callback: @escaping ((_ array: [Powertrain]) -> Void)) throws -> Void + func complexEnumCallback(array: [Powertrain], callback: @escaping (_ array: [Powertrain]) -> Void) throws -> Void func createMap() throws -> AnyMapHolder func mapRoundtrip(map: AnyMapHolder) throws -> AnyMapHolder func funcThatThrows() throws -> Double @@ -51,14 +52,15 @@ public protocol HybridTestObjectSwiftKotlinSpec_protocol: AnyObject { func awaitAndGetPromise(promise: Promise) throws -> Promise func awaitAndGetComplexPromise(promise: Promise) throws -> Promise func awaitPromise(promise: Promise) throws -> Promise - func callCallback(callback: @escaping (() -> Void)) throws -> Void - func callAll(first: @escaping (() -> Void), second: @escaping (() -> Void), third: @escaping (() -> Void)) throws -> Void - func callWithOptional(value: Double?, callback: @escaping ((_ maybe: Double?) -> Void)) throws -> Void - func callSumUpNTimes(callback: @escaping (() -> Promise), n: Double) throws -> Promise - func callbackAsyncPromise(callback: @escaping (() -> Promise>)) throws -> Promise - func callbackAsyncPromiseBuffer(callback: @escaping (() -> Promise>)) throws -> Promise - func getValueFromJSCallbackAndWait(getValue: @escaping (() -> Promise)) throws -> Promise - func getValueFromJsCallback(callback: @escaping (() -> Promise), andThenCall: @escaping ((_ valueFromJs: String) -> Void)) throws -> Promise + func callCallback(callback: @escaping () -> Void) throws -> Void + func callAll(first: @escaping () -> Void, second: @escaping () -> Void, third: @escaping () -> Void) throws -> Void + func callWithOptional(value: Double?, callback: @escaping (_ maybe: Double?) -> Void) throws -> Void + func callSumUpNTimes(callback: @escaping () -> Promise, n: Double) throws -> Promise + func callbackAsyncPromise(callback: @escaping () -> Promise>) throws -> Promise + func callbackAsyncPromiseBuffer(callback: @escaping () -> Promise>) throws -> Promise + func getComplexCallback() throws -> (_ value: Double) -> Void + func getValueFromJSCallbackAndWait(getValue: @escaping () -> Promise) throws -> Promise + func getValueFromJsCallback(callback: @escaping () -> Promise, andThenCall: @escaping (_ valueFromJs: String) -> Void) throws -> Promise func getCar() throws -> Car func isCarElectric(car: Car) throws -> Bool func getDriver(car: Car) throws -> Person? diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift index d9dfd4e2d..0d52f2ca1 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift @@ -313,6 +313,37 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { } } + public var optionalCallback: bridge.std__optional_std__function_void_double____value______ { + @inline(__always) + get { + return { () -> bridge.std__optional_std__function_void_double____value______ in + if let __unwrappedValue = self.__implementation.optionalCallback { + return bridge.create_std__optional_std__function_void_double____value______({ () -> bridge.Func_void_double in + let __closureWrapper = Func_void_double(__unwrappedValue) + return bridge.create_Func_void_double(__closureWrapper.toUnsafe()) + }()) + } else { + return .init() + } + }() + } + @inline(__always) + set { + self.__implementation.optionalCallback = { () -> ((_ value: Double) -> Void)? in + if let __unwrapped = newValue.value { + return { () -> (Double) -> Void in + let __wrappedFunction = bridge.wrap_Func_void_double(__unwrapped) + return { (__value: Double) -> Void in + __wrappedFunction.call(__value) + } + }() + } else { + return nil + } + }() + } + } + public var someVariant: bridge.std__variant_std__string__double_ { @inline(__always) get { @@ -479,7 +510,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func complexEnumCallback(array: bridge.std__vector_Powertrain_, callback: bridge.Func_void_std__vector_Powertrain_) -> bridge.Result_void_ { do { - try self.__implementation.complexEnumCallback(array: array.map({ __item in __item }), callback: { () -> (([Powertrain]) -> Void) in + try self.__implementation.complexEnumCallback(array: array.map({ __item in __item }), callback: { () -> ([Powertrain]) -> Void in let __wrappedFunction = bridge.wrap_Func_void_std__vector_Powertrain_(callback) return { (__array: [Powertrain]) -> Void in __wrappedFunction.call({ () -> bridge.std__vector_Powertrain_ in @@ -799,7 +830,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func callCallback(callback: bridge.Func_void) -> bridge.Result_void_ { do { - try self.__implementation.callCallback(callback: { () -> (() -> Void) in + try self.__implementation.callCallback(callback: { () -> () -> Void in let __wrappedFunction = bridge.wrap_Func_void(callback) return { () -> Void in __wrappedFunction.call() @@ -815,17 +846,17 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func callAll(first: bridge.Func_void, second: bridge.Func_void, third: bridge.Func_void) -> bridge.Result_void_ { do { - try self.__implementation.callAll(first: { () -> (() -> Void) in + try self.__implementation.callAll(first: { () -> () -> Void in let __wrappedFunction = bridge.wrap_Func_void(first) return { () -> Void in __wrappedFunction.call() } - }(), second: { () -> (() -> Void) in + }(), second: { () -> () -> Void in let __wrappedFunction = bridge.wrap_Func_void(second) return { () -> Void in __wrappedFunction.call() } - }(), third: { () -> (() -> Void) in + }(), third: { () -> () -> Void in let __wrappedFunction = bridge.wrap_Func_void(third) return { () -> Void in __wrappedFunction.call() @@ -841,7 +872,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func callWithOptional(value: bridge.std__optional_double_, callback: bridge.Func_void_std__optional_double_) -> bridge.Result_void_ { do { - try self.__implementation.callWithOptional(value: value.value, callback: { () -> ((Double?) -> Void) in + try self.__implementation.callWithOptional(value: value.value, callback: { () -> (Double?) -> Void in let __wrappedFunction = bridge.wrap_Func_void_std__optional_double_(callback) return { (__maybe: Double?) -> Void in __wrappedFunction.call({ () -> bridge.std__optional_double_ in @@ -863,7 +894,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func callSumUpNTimes(callback: bridge.Func_std__shared_ptr_Promise_double__, n: Double) -> bridge.Result_std__shared_ptr_Promise_double___ { do { - let __result = try self.__implementation.callSumUpNTimes(callback: { () -> (() -> Promise) in + let __result = try self.__implementation.callSumUpNTimes(callback: { () -> () -> Promise in let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_double__(callback) return { () -> Promise in let __result = __wrappedFunction.call() @@ -908,7 +939,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func callbackAsyncPromise(callback: bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____) -> bridge.Result_std__shared_ptr_Promise_double___ { do { - let __result = try self.__implementation.callbackAsyncPromise(callback: { () -> (() -> Promise>) in + let __result = try self.__implementation.callbackAsyncPromise(callback: { () -> () -> Promise> in let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(callback) return { () -> Promise> in let __result = __wrappedFunction.call() @@ -953,7 +984,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func callbackAsyncPromiseBuffer(callback: bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____) -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____ { do { - let __result = try self.__implementation.callbackAsyncPromiseBuffer(callback: { () -> (() -> Promise>) in + let __result = try self.__implementation.callbackAsyncPromiseBuffer(callback: { () -> () -> Promise> in let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer_____(callback) return { () -> Promise> in let __result = __wrappedFunction.call() @@ -995,10 +1026,25 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { } } + @inline(__always) + public func getComplexCallback() -> bridge.Result_std__function_void_double____value______ { + do { + let __result = try self.__implementation.getComplexCallback() + let __resultCpp = { () -> bridge.Func_void_double in + let __closureWrapper = Func_void_double(__result) + return bridge.create_Func_void_double(__closureWrapper.toUnsafe()) + }() + return bridge.create_Result_std__function_void_double____value______(__resultCpp) + } catch (let __error) { + let __exceptionPtr = __error.toCpp() + return bridge.create_Result_std__function_void_double____value______(__exceptionPtr) + } + } + @inline(__always) public func getValueFromJSCallbackAndWait(getValue: bridge.Func_std__shared_ptr_Promise_double__) -> bridge.Result_std__shared_ptr_Promise_double___ { do { - let __result = try self.__implementation.getValueFromJSCallbackAndWait(getValue: { () -> (() -> Promise) in + let __result = try self.__implementation.getValueFromJSCallbackAndWait(getValue: { () -> () -> Promise in let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_double__(getValue) return { () -> Promise in let __result = __wrappedFunction.call() @@ -1043,7 +1089,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { @inline(__always) public func getValueFromJsCallback(callback: bridge.Func_std__shared_ptr_Promise_std__string__, andThenCall: bridge.Func_void_std__string) -> bridge.Result_std__shared_ptr_Promise_void___ { do { - let __result = try self.__implementation.getValueFromJsCallback(callback: { () -> (() -> Promise) in + let __result = try self.__implementation.getValueFromJsCallback(callback: { () -> () -> Promise in let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__string__(callback) return { () -> Promise in let __result = __wrappedFunction.call() @@ -1069,7 +1115,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { return __promise }() } - }(), andThenCall: { () -> ((String) -> Void) in + }(), andThenCall: { () -> (String) -> Void in let __wrappedFunction = bridge.wrap_Func_void_std__string(andThenCall) return { (__valueFromJs: String) -> Void in __wrappedFunction.call(std.string(__valueFromJs)) diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/JsStyleStruct.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/JsStyleStruct.swift index d7d74cd12..133620d14 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/JsStyleStruct.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/JsStyleStruct.swift @@ -18,7 +18,7 @@ public extension JsStyleStruct { /** * Create a new instance of `JsStyleStruct`. */ - init(value: Double, onChanged: @escaping ((_ num: Double) -> Void)) { + init(value: Double, onChanged: @escaping (_ num: Double) -> Void) { self.init(value, { () -> bridge.Func_void_double in let __closureWrapper = Func_void_double(onChanged) return bridge.create_Func_void_double(__closureWrapper.toUnsafe()) @@ -36,10 +36,10 @@ public extension JsStyleStruct { } } - var onChanged: ((_ num: Double) -> Void) { + var onChanged: (_ num: Double) -> Void { @inline(__always) get { - return { () -> ((Double) -> Void) in + return { () -> (Double) -> Void in let __wrappedFunction = bridge.wrap_Func_void_double(self.__onChanged) return { (__num: Double) -> Void in __wrappedFunction.call(__num) 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 18e78c219..4085d3fef 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 @@ -39,6 +39,8 @@ namespace margelo::nitro::image { prototype.registerHybridSetter("optionalEnum", &HybridTestObjectCppSpec::setOptionalEnum); prototype.registerHybridGetter("optionalOldEnum", &HybridTestObjectCppSpec::getOptionalOldEnum); prototype.registerHybridSetter("optionalOldEnum", &HybridTestObjectCppSpec::setOptionalOldEnum); + prototype.registerHybridGetter("optionalCallback", &HybridTestObjectCppSpec::getOptionalCallback); + prototype.registerHybridSetter("optionalCallback", &HybridTestObjectCppSpec::setOptionalCallback); prototype.registerHybridGetter("someVariant", &HybridTestObjectCppSpec::getSomeVariant); prototype.registerHybridSetter("someVariant", &HybridTestObjectCppSpec::setSomeVariant); prototype.registerHybridMethod("passVariant", &HybridTestObjectCppSpec::passVariant); @@ -79,6 +81,7 @@ namespace margelo::nitro::image { prototype.registerHybridMethod("callSumUpNTimes", &HybridTestObjectCppSpec::callSumUpNTimes); prototype.registerHybridMethod("callbackAsyncPromise", &HybridTestObjectCppSpec::callbackAsyncPromise); prototype.registerHybridMethod("callbackAsyncPromiseBuffer", &HybridTestObjectCppSpec::callbackAsyncPromiseBuffer); + prototype.registerHybridMethod("getComplexCallback", &HybridTestObjectCppSpec::getComplexCallback); prototype.registerHybridMethod("getValueFromJSCallbackAndWait", &HybridTestObjectCppSpec::getValueFromJSCallbackAndWait); prototype.registerHybridMethod("getValueFromJsCallback", &HybridTestObjectCppSpec::getValueFromJsCallback); prototype.registerHybridMethod("getCar", &HybridTestObjectCppSpec::getCar); 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 6227515de..fa86085cc 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 @@ -42,10 +42,10 @@ namespace margelo::nitro::image { class HybridBaseSpec; } #include #include "Powertrain.hpp" #include "OldEnum.hpp" +#include #include #include "Car.hpp" #include "Person.hpp" -#include #include #include #include @@ -106,6 +106,8 @@ namespace margelo::nitro::image { virtual void setOptionalEnum(std::optional optionalEnum) = 0; virtual std::optional getOptionalOldEnum() = 0; virtual void setOptionalOldEnum(std::optional optionalOldEnum) = 0; + virtual std::optional> getOptionalCallback() = 0; + virtual void setOptionalCallback(const std::optional>& optionalCallback) = 0; virtual std::variant getSomeVariant() = 0; virtual void setSomeVariant(const std::variant& someVariant) = 0; @@ -149,6 +151,7 @@ namespace margelo::nitro::image { virtual std::shared_ptr> callSumUpNTimes(const std::function>()>& callback, double n) = 0; virtual std::shared_ptr> callbackAsyncPromise(const std::function>>>()>& callback) = 0; virtual std::shared_ptr>> callbackAsyncPromiseBuffer(const std::function>>>>()>& callback) = 0; + virtual std::function getComplexCallback() = 0; virtual std::shared_ptr> getValueFromJSCallbackAndWait(const std::function>()>& getValue) = 0; virtual std::shared_ptr> getValueFromJsCallback(const std::function>()>& callback, const std::function& andThenCall) = 0; virtual Car getCar() = 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 a89f9306c..20bd61535 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 @@ -37,6 +37,8 @@ namespace margelo::nitro::image { prototype.registerHybridSetter("optionalEnum", &HybridTestObjectSwiftKotlinSpec::setOptionalEnum); prototype.registerHybridGetter("optionalOldEnum", &HybridTestObjectSwiftKotlinSpec::getOptionalOldEnum); prototype.registerHybridSetter("optionalOldEnum", &HybridTestObjectSwiftKotlinSpec::setOptionalOldEnum); + prototype.registerHybridGetter("optionalCallback", &HybridTestObjectSwiftKotlinSpec::getOptionalCallback); + prototype.registerHybridSetter("optionalCallback", &HybridTestObjectSwiftKotlinSpec::setOptionalCallback); prototype.registerHybridGetter("someVariant", &HybridTestObjectSwiftKotlinSpec::getSomeVariant); prototype.registerHybridSetter("someVariant", &HybridTestObjectSwiftKotlinSpec::setSomeVariant); prototype.registerHybridMethod("newTestObject", &HybridTestObjectSwiftKotlinSpec::newTestObject); @@ -70,6 +72,7 @@ namespace margelo::nitro::image { prototype.registerHybridMethod("callSumUpNTimes", &HybridTestObjectSwiftKotlinSpec::callSumUpNTimes); prototype.registerHybridMethod("callbackAsyncPromise", &HybridTestObjectSwiftKotlinSpec::callbackAsyncPromise); prototype.registerHybridMethod("callbackAsyncPromiseBuffer", &HybridTestObjectSwiftKotlinSpec::callbackAsyncPromiseBuffer); + prototype.registerHybridMethod("getComplexCallback", &HybridTestObjectSwiftKotlinSpec::getComplexCallback); prototype.registerHybridMethod("getValueFromJSCallbackAndWait", &HybridTestObjectSwiftKotlinSpec::getValueFromJSCallbackAndWait); prototype.registerHybridMethod("getValueFromJsCallback", &HybridTestObjectSwiftKotlinSpec::getValueFromJsCallback); prototype.registerHybridMethod("getCar", &HybridTestObjectSwiftKotlinSpec::getCar); 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 d90f62fb8..552dded2d 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 @@ -41,9 +41,9 @@ namespace margelo::nitro::image { class HybridBaseSpec; } #include #include "Powertrain.hpp" #include "OldEnum.hpp" +#include #include #include "Person.hpp" -#include #include #include #include @@ -103,6 +103,8 @@ namespace margelo::nitro::image { virtual void setOptionalEnum(std::optional optionalEnum) = 0; virtual std::optional getOptionalOldEnum() = 0; virtual void setOptionalOldEnum(std::optional optionalOldEnum) = 0; + virtual std::optional> getOptionalCallback() = 0; + virtual void setOptionalCallback(const std::optional>& optionalCallback) = 0; virtual std::variant getSomeVariant() = 0; virtual void setSomeVariant(const std::variant& someVariant) = 0; @@ -139,6 +141,7 @@ namespace margelo::nitro::image { virtual std::shared_ptr> callSumUpNTimes(const std::function>()>& callback, double n) = 0; virtual std::shared_ptr> callbackAsyncPromise(const std::function>>>()>& callback) = 0; virtual std::shared_ptr>> callbackAsyncPromiseBuffer(const std::function>>>>()>& callback) = 0; + virtual std::function getComplexCallback() = 0; virtual std::shared_ptr> getValueFromJSCallbackAndWait(const std::function>()>& getValue) = 0; virtual std::shared_ptr> getValueFromJsCallback(const std::function>()>& callback, const std::function& andThenCall) = 0; virtual Car getCar() = 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 3f19f67db..3cda1a13a 100644 --- a/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts +++ b/packages/react-native-nitro-image/src/specs/TestObject.nitro.ts @@ -56,6 +56,7 @@ interface SharedTestObjectProps { optionalArray?: string[] optionalEnum?: Powertrain optionalOldEnum?: OldEnum + optionalCallback?: (value: number) => void // Basic function tests simpleFunc(): void @@ -113,6 +114,7 @@ interface SharedTestObjectProps { callbackAsyncPromiseBuffer( callback: () => Promise ): Promise + getComplexCallback(): (value: number) => void // Callbacks that return values getValueFromJSCallbackAndWait(getValue: () => number): Promise