Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions example/src/getTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,26 @@ export function getTests(
.didNotThrow()
.equals(false)
),
createTest('areStructOfEnumsEqual(...) same struct', () =>
it(() =>
testObject.areStructOfEnumsEqual(
{ powertrain: 'electric', oldEnum: OldEnum.FIRST },
{ powertrain: 'electric', oldEnum: OldEnum.FIRST }
)
)
.didNotThrow()
.equals(true)
),
createTest('areStructOfEnumsEqual(...) different structs', () =>
it(() =>
testObject.areStructOfEnumsEqual(
{ powertrain: 'electric', oldEnum: OldEnum.FIRST },
{ powertrain: 'gas', oldEnum: OldEnum.SECOND }
)
)
.didNotThrow()
.equals(false)
),
createTest('getDriver(...) with no driver', () =>
it(() =>
testObject.getDriver({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ class HybridTestObjectKotlin : HybridTestObjectSwiftKotlinSpec() {
a.someVariant == b.someVariant
}

override fun areStructOfEnumsEqual(
left: StructOfEnums,
right: StructOfEnums,
): Boolean {
return left == right
}

override fun getDriver(car: Car): Person? {
return car.driver
}
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-nitro-test/cpp/HybridTestObjectCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ bool HybridTestObjectCpp::areCarsEqual(const Car& a, const Car& b) {
return a == b;
}

bool HybridTestObjectCpp::areStructOfEnumsEqual(const StructOfEnums& left, const StructOfEnums& right) {
return left == right;
}

std::optional<Person> HybridTestObjectCpp::getDriver(const Car& car) {
if (car.driver.has_value()) {
return car.driver.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class HybridTestObjectCpp : public HybridTestObjectCppSpec {
Car getCar() override;
bool isCarElectric(const Car& car) override;
bool areCarsEqual(const Car& a, const Car& b) override;
bool areStructOfEnumsEqual(const StructOfEnums& left, const StructOfEnums& right) override;
std::optional<Person> getDriver(const Car& car) override;
Car bounceCar(const Car& car) override;
void jsStyleObjectAsParameters(const JsStyleStruct& params) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ class HybridTestObjectSwift: HybridTestObjectSwiftKotlinSpec {
return a == b
}

func areStructOfEnumsEqual(left: StructOfEnums, right: StructOfEnums) throws -> Bool {
return left == right
}

func getDriver(car: Car) throws -> Person? {
return car.driver
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace margelo::nitro::test { struct ExternalObjectStruct; }
namespace margelo::nitro::test { struct MapWrapper; }
// Forward declaration of `SecondMapWrapper` to properly resolve imports.
namespace margelo::nitro::test { struct SecondMapWrapper; }
// Forward declaration of `StructOfEnums` to properly resolve imports.
namespace margelo::nitro::test { struct StructOfEnums; }
// Forward declaration of `HybridTestViewSpec` to properly resolve imports.
namespace margelo::nitro::test { class HybridTestViewSpec; }

Expand Down Expand Up @@ -121,6 +123,8 @@ namespace margelo::nitro::test { class HybridTestViewSpec; }
#include "JFunc_void_std__string.hpp"
#include "JFunc_void_std__exception_ptr.hpp"
#include "JFunc_std__shared_ptr_Promise_std__string__.hpp"
#include "StructOfEnums.hpp"
#include "JStructOfEnums.hpp"
#include "JVariant_Boolean_DoubleArray_Array_String__String_Double.hpp"
#include "JFunc_double.hpp"
#include "HybridTestViewSpec.hpp"
Expand Down Expand Up @@ -1132,6 +1136,11 @@ namespace margelo::nitro::test {
auto __result = method(_javaPart, JCar::fromCpp(a), JCar::fromCpp(b));
return static_cast<bool>(__result);
}
bool JHybridTestObjectSwiftKotlinSpec::areStructOfEnumsEqual(const StructOfEnums& left, const StructOfEnums& right) {
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean(jni::alias_ref<JStructOfEnums> /* left */, jni::alias_ref<JStructOfEnums> /* right */)>("areStructOfEnumsEqual");
auto __result = method(_javaPart, JStructOfEnums::fromCpp(left), JStructOfEnums::fromCpp(right));
return static_cast<bool>(__result);
}
std::optional<Person> JHybridTestObjectSwiftKotlinSpec::getDriver(const Car& car) {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPerson>(jni::alias_ref<JCar> /* car */)>("getDriver");
auto __result = method(_javaPart, JCar::fromCpp(car));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ namespace margelo::nitro::test {
Car getCar() override;
bool isCarElectric(const Car& car) override;
bool areCarsEqual(const Car& a, const Car& b) override;
bool areStructOfEnumsEqual(const StructOfEnums& left, const StructOfEnums& right) override;
std::optional<Person> getDriver(const Car& car) override;
Car bounceCar(const Car& car) override;
void jsStyleObjectAsParameters(const JsStyleStruct& params) override;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
///
/// JStructOfEnums.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include "StructOfEnums.hpp"

#include "JOldEnum.hpp"
#include "JPowertrain.hpp"
#include "OldEnum.hpp"
#include "Powertrain.hpp"

namespace margelo::nitro::test {

using namespace facebook;

/**
* The C++ JNI bridge between the C++ struct "StructOfEnums" and the the Kotlin data class "StructOfEnums".
*/
struct JStructOfEnums final: public jni::JavaClass<JStructOfEnums> {
public:
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/test/StructOfEnums;";

public:
/**
* Convert this Java/Kotlin-based struct to the C++ struct StructOfEnums by copying all values to C++.
*/
[[maybe_unused]]
[[nodiscard]]
StructOfEnums toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldPowertrain = clazz->getField<JPowertrain>("powertrain");
jni::local_ref<JPowertrain> powertrain = this->getFieldValue(fieldPowertrain);
static const auto fieldOldEnum = clazz->getField<JOldEnum>("oldEnum");
jni::local_ref<JOldEnum> oldEnum = this->getFieldValue(fieldOldEnum);
return StructOfEnums(
powertrain->toCpp(),
oldEnum->toCpp()
);
}

public:
/**
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
*/
[[maybe_unused]]
static jni::local_ref<JStructOfEnums::javaobject> fromCpp(const StructOfEnums& value) {
using JSignature = JStructOfEnums(jni::alias_ref<JPowertrain>, jni::alias_ref<JOldEnum>);
static const auto clazz = javaClassStatic();
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
return create(
clazz,
JPowertrain::fromCpp(value.powertrain),
JOldEnum::fromCpp(value.oldEnum)
);
}
};

} // namespace margelo::nitro::test
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ abstract class HybridTestObjectSwiftKotlinSpec: HybridObject() {
@Keep
abstract fun areCarsEqual(a: Car, b: Car): Boolean

@DoNotStrip
@Keep
abstract fun areStructOfEnumsEqual(left: StructOfEnums, right: StructOfEnums): Boolean

@DoNotStrip
@Keep
abstract fun getDriver(car: Car): Person?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
///
/// StructOfEnums.kt
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///

package com.margelo.nitro.test

import androidx.annotation.Keep
import com.facebook.proguard.annotations.DoNotStrip
import java.util.Objects


/**
* Represents the JavaScript object/struct "StructOfEnums".
*/
@DoNotStrip
@Keep
data class StructOfEnums(
@DoNotStrip
@Keep
val powertrain: Powertrain,
@DoNotStrip
@Keep
val oldEnum: OldEnum
) {
/* primary constructor */

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is StructOfEnums) return false
return Objects.deepEquals(this.powertrain, other.powertrain)
&& Objects.deepEquals(this.oldEnum, other.oldEnum)
}

override fun hashCode(): Int {
return arrayOf(
powertrain,
oldEnum
).contentDeepHashCode()
}

companion object {
/**
* Constructor called from C++
*/
@DoNotStrip
@Keep
@Suppress("unused")
@JvmStatic
private fun fromCpp(powertrain: Powertrain, oldEnum: OldEnum): StructOfEnums {
return StructOfEnums(powertrain, oldEnum)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace margelo::nitro::test { struct Person; }
namespace margelo::nitro::test { enum class Powertrain; }
// Forward declaration of `SecondMapWrapper` to properly resolve imports.
namespace margelo::nitro::test { struct SecondMapWrapper; }
// Forward declaration of `StructOfEnums` to properly resolve imports.
namespace margelo::nitro::test { struct StructOfEnums; }
// Forward declaration of `WeirdNumbersEnum` to properly resolve imports.
namespace margelo::nitro::test { enum class WeirdNumbersEnum; }
// Forward declaration of `WrappedJsStruct` to properly resolve imports.
Expand All @@ -70,6 +72,7 @@ namespace margelo::nitro::test { struct WrappedJsStruct; }
#include "Person.hpp"
#include "Powertrain.hpp"
#include "SecondMapWrapper.hpp"
#include "StructOfEnums.hpp"
#include "WeirdNumbersEnum.hpp"
#include "WrappedJsStruct.hpp"
#include <NitroModules/AnyMap.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace NitroModules { class ArrayBufferHolder; }
namespace margelo::nitro::test { struct MapWrapper; }
// Forward declaration of `SecondMapWrapper` to properly resolve imports.
namespace margelo::nitro::test { struct SecondMapWrapper; }
// Forward declaration of `StructOfEnums` to properly resolve imports.
namespace margelo::nitro::test { struct StructOfEnums; }
// Forward declaration of `JsStyleStruct` to properly resolve imports.
namespace margelo::nitro::test { struct JsStyleStruct; }
// Forward declaration of `WrappedJsStruct` to properly resolve imports.
Expand Down Expand Up @@ -74,6 +76,7 @@ namespace margelo::nitro::test { struct ExternalObjectStruct; }
#include "SecondMapWrapper.hpp"
#include <exception>
#include <chrono>
#include "StructOfEnums.hpp"
#include "JsStyleStruct.hpp"
#include "WrappedJsStruct.hpp"
#include "OptionalWrapper.hpp"
Expand Down Expand Up @@ -742,6 +745,14 @@ namespace margelo::nitro::test {
auto __value = std::move(__result.value());
return __value;
}
inline bool areStructOfEnumsEqual(const StructOfEnums& left, const StructOfEnums& right) override {
auto __result = _swiftPart.areStructOfEnumsEqual(std::forward<decltype(left)>(left), std::forward<decltype(right)>(right));
if (__result.hasError()) [[unlikely]] {
std::rethrow_exception(__result.error());
}
auto __value = std::move(__result.value());
return __value;
}
inline std::optional<Person> getDriver(const Car& car) override {
auto __result = _swiftPart.getDriver(std::forward<decltype(car)>(car));
if (__result.hasError()) [[unlikely]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public protocol HybridTestObjectSwiftKotlinSpec_protocol: HybridObject {
func getCar() throws -> Car
func isCarElectric(car: Car) throws -> Bool
func areCarsEqual(a: Car, b: Car) throws -> Bool
func areStructOfEnumsEqual(left: StructOfEnums, right: StructOfEnums) throws -> Bool
func getDriver(car: Car) throws -> Person?
func bounceCar(car: Car) throws -> Car
func jsStyleObjectAsParameters(params: JsStyleStruct) throws -> Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
get {
return { () -> bridge.std__variant_nitro__NullType__std__string_ in
switch self.__implementation.stringOrNull {
case .first(let __value):

Check warning on line 285 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Build iOS Example App (static_frameworks, static)

immutable value '__value' was never used; consider replacing with '_' or removing it

Check warning on line 285 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Build iOS Example App (no_frameworks)

immutable value '__value' was never used; consider replacing with '_' or removing it

Check warning on line 285 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Harness iOS (new architecture)

immutable value '__value' was never used; consider replacing with '_' or removing it
return bridge.create_std__variant_nitro__NullType__std__string_(margelo.nitro.NullType.null)
case .second(let __value):
return bridge.create_std__variant_nitro__NullType__std__string_(std.string(__value))
Expand All @@ -295,7 +295,7 @@
let __variant = newValue
switch __variant.index() {
case 0:
let __actual = __variant.get_0()

Check warning on line 298 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Build iOS Example App (static_frameworks, static)

initialization of immutable value '__actual' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 298 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Build iOS Example App (no_frameworks)

initialization of immutable value '__actual' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 298 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Harness iOS (new architecture)

initialization of immutable value '__actual' was never used; consider replacing with assignment to '_' or removing it
return .first(NullType.null)
case 1:
let __actual = __variant.get_1()
Expand Down Expand Up @@ -572,7 +572,7 @@
@inline(__always)
public final func bounceNull(value: margelo.nitro.NullType) -> bridge.Result_nitro__NullType_ {
do {
let __result = try self.__implementation.bounceNull(value: NullType.null)

Check warning on line 575 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Build iOS Example App (static_frameworks, static)

initialization of immutable value '__result' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 575 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Build iOS Example App (no_frameworks)

initialization of immutable value '__result' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 575 in packages/react-native-nitro-test/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift

View workflow job for this annotation

GitHub Actions / Harness iOS (new architecture)

initialization of immutable value '__result' was never used; consider replacing with assignment to '_' or removing it
let __resultCpp = margelo.nitro.NullType.null
return bridge.create_Result_nitro__NullType_(__resultCpp)
} catch (let __error) {
Expand Down Expand Up @@ -1861,6 +1861,18 @@
}
}

@inline(__always)
public final func areStructOfEnumsEqual(left: StructOfEnums, right: StructOfEnums) -> bridge.Result_bool_ {
do {
let __result = try self.__implementation.areStructOfEnumsEqual(left: left, right: right)
let __resultCpp = __result
return bridge.create_Result_bool_(__resultCpp)
} catch (let __error) {
let __exceptionPtr = __error.toCpp()
return bridge.create_Result_bool_(__exceptionPtr)
}
}

@inline(__always)
public final func getDriver(car: Car) -> bridge.Result_std__optional_Person__ {
do {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
///
/// StructOfEnums.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///

import NitroModules

/**
* Represents an instance of `StructOfEnums`, backed by a C++ struct.
*/
public typealias StructOfEnums = margelo.nitro.test.StructOfEnums

public extension StructOfEnums {
private typealias bridge = margelo.nitro.test.bridge.swift

/**
* Create a new instance of `StructOfEnums`.
*/
init(powertrain: Powertrain, oldEnum: OldEnum) {
self.init(powertrain, oldEnum)
}

@inline(__always)
var powertrain: Powertrain {
return self.__powertrain
}

@inline(__always)
var oldEnum: OldEnum {
return self.__oldEnum
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ namespace margelo::nitro::test {
prototype.registerHybridMethod("getCar", &HybridTestObjectCppSpec::getCar);
prototype.registerHybridMethod("isCarElectric", &HybridTestObjectCppSpec::isCarElectric);
prototype.registerHybridMethod("areCarsEqual", &HybridTestObjectCppSpec::areCarsEqual);
prototype.registerHybridMethod("areStructOfEnumsEqual", &HybridTestObjectCppSpec::areStructOfEnumsEqual);
prototype.registerHybridMethod("getDriver", &HybridTestObjectCppSpec::getDriver);
prototype.registerHybridMethod("bounceCar", &HybridTestObjectCppSpec::bounceCar);
prototype.registerHybridMethod("jsStyleObjectAsParameters", &HybridTestObjectCppSpec::jsStyleObjectAsParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace margelo::nitro::test { struct Car; }
namespace margelo::nitro::test { class HybridChildSpec; }
// Forward declaration of `MapWrapper` to properly resolve imports.
namespace margelo::nitro::test { struct MapWrapper; }
// Forward declaration of `StructOfEnums` to properly resolve imports.
namespace margelo::nitro::test { struct StructOfEnums; }
// Forward declaration of `JsStyleStruct` to properly resolve imports.
namespace margelo::nitro::test { struct JsStyleStruct; }
// Forward declaration of `WrappedJsStruct` to properly resolve imports.
Expand Down Expand Up @@ -74,6 +76,7 @@ namespace margelo::nitro::test { struct ExternalObjectStruct; }
#include "MapWrapper.hpp"
#include <exception>
#include <chrono>
#include "StructOfEnums.hpp"
#include "JsStyleStruct.hpp"
#include "WrappedJsStruct.hpp"
#include "OptionalWrapper.hpp"
Expand Down Expand Up @@ -221,6 +224,7 @@ namespace margelo::nitro::test {
virtual Car getCar() = 0;
virtual bool isCarElectric(const Car& car) = 0;
virtual bool areCarsEqual(const Car& a, const Car& b) = 0;
virtual bool areStructOfEnumsEqual(const StructOfEnums& left, const StructOfEnums& right) = 0;
virtual std::optional<Person> getDriver(const Car& car) = 0;
virtual Car bounceCar(const Car& car) = 0;
virtual void jsStyleObjectAsParameters(const JsStyleStruct& params) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace margelo::nitro::test {
prototype.registerHybridMethod("getCar", &HybridTestObjectSwiftKotlinSpec::getCar);
prototype.registerHybridMethod("isCarElectric", &HybridTestObjectSwiftKotlinSpec::isCarElectric);
prototype.registerHybridMethod("areCarsEqual", &HybridTestObjectSwiftKotlinSpec::areCarsEqual);
prototype.registerHybridMethod("areStructOfEnumsEqual", &HybridTestObjectSwiftKotlinSpec::areStructOfEnumsEqual);
prototype.registerHybridMethod("getDriver", &HybridTestObjectSwiftKotlinSpec::getDriver);
prototype.registerHybridMethod("bounceCar", &HybridTestObjectSwiftKotlinSpec::bounceCar);
prototype.registerHybridMethod("jsStyleObjectAsParameters", &HybridTestObjectSwiftKotlinSpec::jsStyleObjectAsParameters);
Expand Down
Loading
Loading