-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix "legacy"
enum
s breaking Swift compiler (#346)
* feat: Add `OldEnum` tests (enum with numbers) * whoops * whoops 2 * fix: Fix `std::optional<enum>` breaking swift compiler * Update SwiftCxxBridgedType.ts
- Loading branch information
Showing
22 changed files
with
246 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/react-native-nitro-image/nitrogen/generated/android/c++/JOldEnum.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/// | ||
/// JOldEnum.hpp | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
#include "OldEnum.hpp" | ||
|
||
namespace margelo::nitro::image { | ||
|
||
using namespace facebook; | ||
|
||
/** | ||
* The C++ JNI bridge between the C++ enum "OldEnum" and the the Kotlin enum "OldEnum". | ||
*/ | ||
struct JOldEnum final: public jni::JavaClass<JOldEnum> { | ||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/OldEnum;"; | ||
|
||
public: | ||
/** | ||
* Convert this Java/Kotlin-based enum to the C++ enum OldEnum. | ||
*/ | ||
[[maybe_unused]] | ||
OldEnum toCpp() const { | ||
static const auto clazz = javaClassStatic(); | ||
static const auto fieldOrdinal = clazz->getField<int>("ordinal"); | ||
int ordinal = this->getFieldValue(fieldOrdinal); | ||
return static_cast<OldEnum>(ordinal); | ||
} | ||
|
||
public: | ||
/** | ||
* Create a Java/Kotlin-based enum with the given C++ enum's value. | ||
*/ | ||
[[maybe_unused]] | ||
static jni::alias_ref<JOldEnum> fromCpp(OldEnum value) { | ||
static const auto clazz = javaClassStatic(); | ||
static const auto fieldFIRST = clazz->getStaticField<JOldEnum>("FIRST"); | ||
static const auto fieldSECOND = clazz->getStaticField<JOldEnum>("SECOND"); | ||
static const auto fieldTHIRD = clazz->getStaticField<JOldEnum>("THIRD"); | ||
|
||
switch (value) { | ||
case OldEnum::FIRST: | ||
return clazz->getStaticFieldValue(fieldFIRST); | ||
case OldEnum::SECOND: | ||
return clazz->getStaticFieldValue(fieldSECOND); | ||
case OldEnum::THIRD: | ||
return clazz->getStaticFieldValue(fieldTHIRD); | ||
default: | ||
std::string stringValue = std::to_string(static_cast<int>(value)); | ||
throw std::invalid_argument("Invalid enum value (" + stringValue + "!"); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace margelo::nitro::image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...t-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/OldEnum.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// | ||
/// OldEnum.kt | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
package com.margelo.nitro.image | ||
|
||
import androidx.annotation.Keep | ||
import com.facebook.proguard.annotations.DoNotStrip | ||
|
||
/** | ||
* Represents the JavaScript enum/union "OldEnum". | ||
*/ | ||
@DoNotStrip | ||
@Keep | ||
enum class OldEnum { | ||
FIRST, | ||
SECOND, | ||
THIRD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.