diff --git a/bun.lock b/bun.lock index cab467a20..b19091798 100644 --- a/bun.lock +++ b/bun.lock @@ -1,6 +1,5 @@ { "lockfileVersion": 1, - "configVersion": 0, "workspaces": { "": { "name": "react-native-nitro", @@ -65,6 +64,7 @@ "react": "19.2.0", "react-native": "0.83.0", "react-native-nitro-modules": "*", + "react-native-nitro-player": "^0.7.0", "react-native-nitro-test": "*", "react-native-nitro-test-external": "*", "react-native-safe-area-context": "^5.6.2", @@ -3429,6 +3429,8 @@ "react-native-nitro-modules": ["react-native-nitro-modules@workspace:packages/react-native-nitro-modules"], + "react-native-nitro-player": ["react-native-nitro-player@0.7.0", "", { "peerDependencies": { "react": "*", "react-native": "*", "react-native-nitro-modules": "*" } }, "sha512-ksEYD+l578oXNZG86MJBtUwWYE7f9JuY7I7V/zVJMc3pbrc8tz0LY961GU1oh3GB1uECD8TdmT6sKLningXXZg=="], + "react-native-nitro-test": ["react-native-nitro-test@workspace:packages/react-native-nitro-test"], "react-native-nitro-test-external": ["react-native-nitro-test-external@workspace:packages/react-native-nitro-test-external"], diff --git a/example/ios/NitroExample.xcodeproj/project.pbxproj b/example/ios/NitroExample.xcodeproj/project.pbxproj index 8ccffb976..18d426bf7 100644 --- a/example/ios/NitroExample.xcodeproj/project.pbxproj +++ b/example/ios/NitroExample.xcodeproj/project.pbxproj @@ -388,8 +388,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = CJW62Q77E7; + DEVELOPMENT_TEAM = Y9326JGWX2; ENABLE_BITCODE = NO; INFOPLIST_FILE = NitroExample/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "Nitro Example"; @@ -405,8 +407,9 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = com.mrousavy.nitro.example; + PRODUCT_BUNDLE_IDENTIFIER = com.mrousavy.nitro.example.akol; PRODUCT_NAME = NitroExample; + PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_INTEROP_MODE = objc; @@ -423,8 +426,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = CJW62Q77E7; + DEVELOPMENT_TEAM = Y9326JGWX2; INFOPLIST_FILE = NitroExample/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "Nitro Example"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools"; @@ -439,8 +444,9 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = com.mrousavy.nitro.example; + PRODUCT_BUNDLE_IDENTIFIER = com.mrousavy.nitro.example.akol; PRODUCT_NAME = NitroExample; + PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_INTEROP_MODE = objc; diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index e480a462a..a9650bc15 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -26,6 +26,30 @@ PODS: - ReactCommon/turbomodule/core - ReactNativeDependencies - Yoga + - NitroPlayer (0.7.0): + - hermes-engine + - NitroModules + - RCTRequired + - RCTTypeSafety + - React-callinvoker + - React-Core + - React-Core-prebuilt + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-renderercss + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - ReactNativeDependencies + - Yoga - NitroTest (0.35.2): - hermes-engine - NitroModules @@ -1976,6 +2000,7 @@ DEPENDENCIES: - FBLazyVector (from `../../node_modules/react-native/Libraries/FBLazyVector`) - hermes-engine (from `../../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - NitroModules (from `../../node_modules/react-native-nitro-modules`) + - NitroPlayer (from `../../node_modules/react-native-nitro-player`) - NitroTest (from `../../node_modules/react-native-nitro-test`) - NitroTestExternal (from `../../node_modules/react-native-nitro-test-external`) - RCTDeprecation (from `../../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`) @@ -2062,6 +2087,8 @@ EXTERNAL SOURCES: :tag: hermes-v0.14.0 NitroModules: :path: "../../node_modules/react-native-nitro-modules" + NitroPlayer: + :path: "../../node_modules/react-native-nitro-player" NitroTest: :path: "../../node_modules/react-native-nitro-test" NitroTestExternal: @@ -2217,8 +2244,9 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: FBLazyVector: 7c1d69992204c5ec452eeefa4a24b0ff311709c8 - hermes-engine: 16e781d7fca74c8bb3ca59b99527d9633ee9ee36 + hermes-engine: 4df240db09b8f56297ca8e63c2a793d538964397 NitroModules: 113b4a704e0d6a436d2c5600d5af41f847b0fdd1 + NitroPlayer: 274fe1f4cae54e6e013fc98f3ffe76d567c3dc63 NitroTest: 69754d44fa98075944565e5df6b321c09f2ee4be NitroTestExternal: 63f62beac90ad88b7c04f02928859441451fb42c RCTDeprecation: dbbb85eae640e3b43cc16462d0476b00ca5959ae @@ -2229,7 +2257,7 @@ SPEC CHECKSUMS: React: f6f8fc5c01e77349cdfaf49102bcb928ac31d8ed React-callinvoker: 3e62a849bda1522c6422309c02f5dc3210bc5359 React-Core: 0b765bc7c2b83dff178c2b03ed8a0390df26f18c - React-Core-prebuilt: 88810feb58457484bff17e9e91a15453407d745a + React-Core-prebuilt: 37f17c7949e91eea47a1b8878c231d9c898f46d5 React-CoreModules: 55b932564ba696301cb683a86385be6a6f137e57 React-cxxreact: 5bfb95256fde56cc0f9ce425f38cfaa085e71ad2 React-debug: f9dda2791d3ebe2078bc6102641edab77917efb7 @@ -2292,9 +2320,9 @@ SPEC CHECKSUMS: ReactAppDependencyProvider: 23e2bca1661f8781e55fcc05a151fc1df97bc1fb ReactCodegen: c049d7e966ed24be56d8e21cb1b8880316975e76 ReactCommon: 89ccc6cb100ca5a0303b46483037ef8f3e06e2e0 - ReactNativeDependencies: 1a7e3c3ffa57533d8118dd9bc01790ffa9e02a3b + ReactNativeDependencies: a482285e53605a6a6f4d3c4221906a65051d584b RNScreens: dd61bc3a3e6f6901ad833efa411917d44827cf51 - Yoga: 21f482cbc18b56cdc477cd3a0c5b8c2c83ac27ce + Yoga: 90687fcd1ebd927341caed917696d692813c0b24 PODFILE CHECKSUM: cc2ab22c5169410d8739c73db2747f1617e7eaf0 diff --git a/example/package.json b/example/package.json index 152444503..f17a1df58 100644 --- a/example/package.json +++ b/example/package.json @@ -25,9 +25,10 @@ "deep-equal": "^2.2.3", "react": "19.2.0", "react-native": "0.83.0", + "react-native-nitro-modules": "*", + "react-native-nitro-player": "^0.7.0", "react-native-nitro-test": "*", "react-native-nitro-test-external": "*", - "react-native-nitro-modules": "*", "react-native-safe-area-context": "^5.6.2", "react-native-screens": "^4.14.0" }, diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternal+autolinking.cmake b/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternal+autolinking.cmake index 79c9340a2..7db895d6b 100644 --- a/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternal+autolinking.cmake +++ b/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternal+autolinking.cmake @@ -34,8 +34,10 @@ target_sources( ../nitrogen/generated/android/NitroTestExternalOnLoad.cpp # Shared Nitrogen C++ sources ../nitrogen/generated/shared/c++/HybridSomeExternalObjectSpec.cpp + ../nitrogen/generated/shared/c++/HybridBaseSpec.cpp # Android-specific Nitrogen C++ sources ../nitrogen/generated/android/c++/JHybridSomeExternalObjectSpec.cpp + ../nitrogen/generated/android/c++/JHybridBaseSpec.cpp ) # From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternalOnLoad.cpp b/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternalOnLoad.cpp index 53a6a8167..02ce80043 100644 --- a/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternalOnLoad.cpp +++ b/packages/react-native-nitro-test-external/nitrogen/generated/android/NitroTestExternalOnLoad.cpp @@ -16,6 +16,7 @@ #include #include "JHybridSomeExternalObjectSpec.hpp" +#include "JHybridBaseSpec.hpp" #include namespace margelo::nitro::test::external { @@ -41,6 +42,7 @@ void registerAllNatives() { // Register native JNI methods margelo::nitro::test::external::JHybridSomeExternalObjectSpec::CxxPart::registerNatives(); + margelo::nitro::test::external::JHybridBaseSpec::CxxPart::registerNatives(); // Register Nitro Hybrid Objects HybridObjectRegistry::registerHybridObjectConstructor( diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/android/c++/JHybridBaseSpec.cpp b/packages/react-native-nitro-test-external/nitrogen/generated/android/c++/JHybridBaseSpec.cpp new file mode 100644 index 000000000..6c2f716b3 --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/android/c++/JHybridBaseSpec.cpp @@ -0,0 +1,53 @@ +/// +/// JHybridBaseSpec.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include "JHybridBaseSpec.hpp" + + + + + +namespace margelo::nitro::test::external { + + std::shared_ptr JHybridBaseSpec::JavaPart::getJHybridBaseSpec() { + auto hybridObject = JHybridObject::JavaPart::getJHybridObject(); + auto castHybridObject = std::dynamic_pointer_cast(hybridObject); + if (castHybridObject == nullptr) [[unlikely]] { + throw std::runtime_error("Failed to downcast JHybridObject to JHybridBaseSpec!"); + } + return castHybridObject; + } + + jni::local_ref JHybridBaseSpec::CxxPart::initHybrid(jni::alias_ref jThis) { + return makeCxxInstance(jThis); + } + + std::shared_ptr JHybridBaseSpec::CxxPart::createHybridObject(const jni::local_ref& javaPart) { + auto castJavaPart = jni::dynamic_ref_cast(javaPart); + if (castJavaPart == nullptr) [[unlikely]] { + throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridBaseSpec::JavaPart!"); + } + return std::make_shared(castJavaPart); + } + + void JHybridBaseSpec::CxxPart::registerNatives() { + registerHybrid({ + makeNativeMethod("initHybrid", JHybridBaseSpec::CxxPart::initHybrid), + }); + } + + // Properties + double JHybridBaseSpec::getBaseValue() { + static const auto method = _javaPart->javaClassStatic()->getMethod("getBaseValue"); + auto __result = method(_javaPart); + return __result; + } + + // Methods + + +} // namespace margelo::nitro::test::external diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/android/c++/JHybridBaseSpec.hpp b/packages/react-native-nitro-test-external/nitrogen/generated/android/c++/JHybridBaseSpec.hpp new file mode 100644 index 000000000..cd84aba8a --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/android/c++/JHybridBaseSpec.hpp @@ -0,0 +1,63 @@ +/// +/// HybridBaseSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include "HybridBaseSpec.hpp" + + + + +namespace margelo::nitro::test::external { + + using namespace facebook; + + class JHybridBaseSpec: public virtual HybridBaseSpec, public virtual JHybridObject { + public: + struct JavaPart: public jni::JavaClass { + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/test/external/HybridBaseSpec;"; + std::shared_ptr getJHybridBaseSpec(); + }; + struct CxxPart: public jni::HybridClass { + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/test/external/HybridBaseSpec$CxxPart;"; + static jni::local_ref initHybrid(jni::alias_ref jThis); + static void registerNatives(); + using HybridBase::HybridBase; + protected: + std::shared_ptr createHybridObject(const jni::local_ref& javaPart) override; + }; + + public: + explicit JHybridBaseSpec(const jni::local_ref& javaPart): + HybridObject(HybridBaseSpec::TAG), + JHybridObject(javaPart), + _javaPart(jni::make_global(javaPart)) {} + ~JHybridBaseSpec() override { + // Hermes GC can destroy JS objects on a non-JNI Thread. + jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); + } + + public: + inline const jni::global_ref& getJavaPart() const noexcept { + return _javaPart; + } + + public: + // Properties + double getBaseValue() override; + + public: + // Methods + + + private: + jni::global_ref _javaPart; + }; + +} // namespace margelo::nitro::test::external diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/android/kotlin/com/margelo/nitro/test/external/HybridBaseSpec.kt b/packages/react-native-nitro-test-external/nitrogen/generated/android/kotlin/com/margelo/nitro/test/external/HybridBaseSpec.kt new file mode 100644 index 000000000..2bdc3cbb6 --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/android/kotlin/com/margelo/nitro/test/external/HybridBaseSpec.kt @@ -0,0 +1,54 @@ +/// +/// HybridBaseSpec.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.external + +import androidx.annotation.Keep +import com.facebook.jni.HybridData +import com.facebook.proguard.annotations.DoNotStrip +import com.margelo.nitro.core.HybridObject + +/** + * A Kotlin class representing the Base HybridObject. + * Implement this abstract class to create Kotlin-based instances of Base. + */ +@DoNotStrip +@Keep +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) +abstract class HybridBaseSpec: HybridObject() { + // Properties + @get:DoNotStrip + @get:Keep + abstract val baseValue: Double + + // Methods + + + // Default implementation of `HybridObject.toString()` + override fun toString(): String { + return "[HybridObject Base]" + } + + // C++ backing class + @DoNotStrip + @Keep + protected open class CxxPart(javaPart: HybridBaseSpec): HybridObject.CxxPart(javaPart) { + // C++ JHybridBaseSpec::CxxPart::initHybrid(...) + external override fun initHybrid(): HybridData + } + override fun createCxxPart(): CxxPart { + return CxxPart(this) + } + + companion object { + protected const val TAG = "HybridBaseSpec" + } +} diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.cpp b/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.cpp index eb8fe3589..1ab42d2f7 100644 --- a/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.cpp +++ b/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.cpp @@ -8,6 +8,7 @@ #include "NitroTestExternal-Swift-Cxx-Bridge.hpp" // Include C++ implementation defined types +#include "HybridBaseSpecSwift.hpp" #include "HybridSomeExternalObjectSpecSwift.hpp" #include "NitroTestExternal-Swift-Cxx-Umbrella.hpp" #include @@ -29,5 +30,21 @@ namespace margelo::nitro::test::external::bridge::swift { NitroTestExternal::HybridSomeExternalObjectSpec_cxx& swiftPart = swiftWrapper->getSwiftPart(); return swiftPart.toUnsafe(); } + + // pragma MARK: std::shared_ptr + std::shared_ptr create_std__shared_ptr_HybridBaseSpec_(void* NON_NULL swiftUnsafePointer) noexcept { + NitroTestExternal::HybridBaseSpec_cxx swiftPart = NitroTestExternal::HybridBaseSpec_cxx::fromUnsafe(swiftUnsafePointer); + return std::make_shared(swiftPart); + } + void* NON_NULL get_std__shared_ptr_HybridBaseSpec_(std__shared_ptr_HybridBaseSpec_ cppType) { + std::shared_ptr swiftWrapper = std::dynamic_pointer_cast(cppType); + #ifdef NITRO_DEBUG + if (swiftWrapper == nullptr) [[unlikely]] { + throw std::runtime_error("Class \"HybridBaseSpec\" is not implemented in Swift!"); + } + #endif + NitroTestExternal::HybridBaseSpec_cxx& swiftPart = swiftWrapper->getSwiftPart(); + return swiftPart.toUnsafe(); + } } // namespace margelo::nitro::test::external::bridge::swift diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.hpp b/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.hpp index a89feb409..35c9e3144 100644 --- a/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.hpp +++ b/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Bridge.hpp @@ -8,16 +8,21 @@ #pragma once // Forward declarations of C++ defined types +// Forward declaration of `HybridBaseSpec` to properly resolve imports. +namespace margelo::nitro::test::external { class HybridBaseSpec; } // Forward declaration of `HybridSomeExternalObjectSpec` to properly resolve imports. namespace margelo::nitro::test::external { class HybridSomeExternalObjectSpec; } // Forward declaration of `OptionalPrimitivesHolder` to properly resolve imports. namespace margelo::nitro::test::external { struct OptionalPrimitivesHolder; } // Forward declarations of Swift defined types +// Forward declaration of `HybridBaseSpec_cxx` to properly resolve imports. +namespace NitroTestExternal { class HybridBaseSpec_cxx; } // Forward declaration of `HybridSomeExternalObjectSpec_cxx` to properly resolve imports. namespace NitroTestExternal { class HybridSomeExternalObjectSpec_cxx; } // Include C++ defined types +#include "HybridBaseSpec.hpp" #include "HybridSomeExternalObjectSpec.hpp" #include "OptionalPrimitivesHolder.hpp" #include @@ -121,5 +126,17 @@ namespace margelo::nitro::test::external::bridge::swift { inline Result_OptionalPrimitivesHolder_ create_Result_OptionalPrimitivesHolder_(const std::exception_ptr& error) noexcept { return Result::withError(error); } + + // pragma MARK: std::shared_ptr + /** + * Specialized version of `std::shared_ptr`. + */ + using std__shared_ptr_HybridBaseSpec_ = std::shared_ptr; + std::shared_ptr create_std__shared_ptr_HybridBaseSpec_(void* NON_NULL swiftUnsafePointer) noexcept; + void* NON_NULL get_std__shared_ptr_HybridBaseSpec_(std__shared_ptr_HybridBaseSpec_ cppType); + + // pragma MARK: std::weak_ptr + using std__weak_ptr_HybridBaseSpec_ = std::weak_ptr; + inline std__weak_ptr_HybridBaseSpec_ weakify_std__shared_ptr_HybridBaseSpec_(const std::shared_ptr& strong) noexcept { return strong; } } // namespace margelo::nitro::test::external::bridge::swift diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Umbrella.hpp b/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Umbrella.hpp index a08536f9e..04c6aa2e3 100644 --- a/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Umbrella.hpp +++ b/packages/react-native-nitro-test-external/nitrogen/generated/ios/NitroTestExternal-Swift-Cxx-Umbrella.hpp @@ -8,12 +8,15 @@ #pragma once // Forward declarations of C++ defined types +// Forward declaration of `HybridBaseSpec` to properly resolve imports. +namespace margelo::nitro::test::external { class HybridBaseSpec; } // Forward declaration of `HybridSomeExternalObjectSpec` to properly resolve imports. namespace margelo::nitro::test::external { class HybridSomeExternalObjectSpec; } // Forward declaration of `OptionalPrimitivesHolder` to properly resolve imports. namespace margelo::nitro::test::external { struct OptionalPrimitivesHolder; } // Include C++ defined types +#include "HybridBaseSpec.hpp" #include "HybridSomeExternalObjectSpec.hpp" #include "OptionalPrimitivesHolder.hpp" #include @@ -32,6 +35,8 @@ namespace margelo::nitro::test::external { struct OptionalPrimitivesHolder; } #include // Forward declarations of Swift defined types +// Forward declaration of `HybridBaseSpec_cxx` to properly resolve imports. +namespace NitroTestExternal { class HybridBaseSpec_cxx; } // Forward declaration of `HybridSomeExternalObjectSpec_cxx` to properly resolve imports. namespace NitroTestExternal { class HybridSomeExternalObjectSpec_cxx; } diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/ios/c++/HybridBaseSpecSwift.cpp b/packages/react-native-nitro-test-external/nitrogen/generated/ios/c++/HybridBaseSpecSwift.cpp new file mode 100644 index 000000000..d72488a72 --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/ios/c++/HybridBaseSpecSwift.cpp @@ -0,0 +1,11 @@ +/// +/// HybridBaseSpecSwift.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include "HybridBaseSpecSwift.hpp" + +namespace margelo::nitro::test::external { +} // namespace margelo::nitro::test::external diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/ios/c++/HybridBaseSpecSwift.hpp b/packages/react-native-nitro-test-external/nitrogen/generated/ios/c++/HybridBaseSpecSwift.hpp new file mode 100644 index 000000000..97a09510d --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/ios/c++/HybridBaseSpecSwift.hpp @@ -0,0 +1,77 @@ +/// +/// HybridBaseSpecSwift.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include "HybridBaseSpec.hpp" + +// Forward declaration of `HybridBaseSpec_cxx` to properly resolve imports. +namespace NitroTestExternal { class HybridBaseSpec_cxx; } + + + + + +#include "NitroTestExternal-Swift-Cxx-Umbrella.hpp" + +namespace margelo::nitro::test::external { + + /** + * The C++ part of HybridBaseSpec_cxx.swift. + * + * HybridBaseSpecSwift (C++) accesses HybridBaseSpec_cxx (Swift), and might + * contain some additional bridging code for C++ <> Swift interop. + * + * Since this obviously introduces an overhead, I hope at some point in + * the future, HybridBaseSpec_cxx can directly inherit from the C++ class HybridBaseSpec + * to simplify the whole structure and memory management. + */ + class HybridBaseSpecSwift: public virtual HybridBaseSpec { + public: + // Constructor from a Swift instance + explicit HybridBaseSpecSwift(const NitroTestExternal::HybridBaseSpec_cxx& swiftPart): + HybridObject(HybridBaseSpec::TAG), + _swiftPart(swiftPart) { } + + public: + // Get the Swift part + inline NitroTestExternal::HybridBaseSpec_cxx& getSwiftPart() noexcept { + return _swiftPart; + } + + public: + inline size_t getExternalMemorySize() noexcept override { + return _swiftPart.getMemorySize(); + } + bool equals(const std::shared_ptr& other) override { + if (auto otherCast = std::dynamic_pointer_cast(other)) { + return _swiftPart.equals(otherCast->_swiftPart); + } + return false; + } + void dispose() noexcept override { + _swiftPart.dispose(); + } + std::string toString() override { + return _swiftPart.toString(); + } + + public: + // Properties + inline double getBaseValue() noexcept override { + return _swiftPart.getBaseValue(); + } + + public: + // Methods + + + private: + NitroTestExternal::HybridBaseSpec_cxx _swiftPart; + }; + +} // namespace margelo::nitro::test::external diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/ios/swift/HybridBaseSpec.swift b/packages/react-native-nitro-test-external/nitrogen/generated/ios/swift/HybridBaseSpec.swift new file mode 100644 index 000000000..322357dc3 --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/ios/swift/HybridBaseSpec.swift @@ -0,0 +1,55 @@ +/// +/// HybridBaseSpec.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +import NitroModules + +/// See ``HybridBaseSpec`` +public protocol HybridBaseSpec_protocol: HybridObject { + // Properties + var baseValue: Double { get } + + // Methods + +} + +public extension HybridBaseSpec_protocol { + /// Default implementation of ``HybridObject.toString`` + func toString() -> String { + return "[HybridObject Base]" + } +} + +/// See ``HybridBaseSpec`` +open class HybridBaseSpec_base { + private weak var cxxWrapper: HybridBaseSpec_cxx? = nil + public init() { } + public func getCxxWrapper() -> HybridBaseSpec_cxx { + #if DEBUG + guard self is any HybridBaseSpec else { + fatalError("`self` is not a `HybridBaseSpec`! Did you accidentally inherit from `HybridBaseSpec_base` instead of `HybridBaseSpec`?") + } + #endif + if let cxxWrapper = self.cxxWrapper { + return cxxWrapper + } else { + let cxxWrapper = HybridBaseSpec_cxx(self as! any HybridBaseSpec) + self.cxxWrapper = cxxWrapper + return cxxWrapper + } + } +} + +/** + * A Swift base-protocol representing the Base HybridObject. + * Implement this protocol to create Swift-based instances of Base. + * ```swift + * class HybridBase : HybridBaseSpec { + * // ... + * } + * ``` + */ +public typealias HybridBaseSpec = HybridBaseSpec_protocol & HybridBaseSpec_base diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/ios/swift/HybridBaseSpec_cxx.swift b/packages/react-native-nitro-test-external/nitrogen/generated/ios/swift/HybridBaseSpec_cxx.swift new file mode 100644 index 000000000..edc7dfed8 --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/ios/swift/HybridBaseSpec_cxx.swift @@ -0,0 +1,133 @@ +/// +/// HybridBaseSpec_cxx.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * A class implementation that bridges HybridBaseSpec over to C++. + * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined. + * + * Also, some Swift types need to be bridged with special handling: + * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330) + * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper + * - Throwing methods need to be wrapped with a Result type, as exceptions cannot be propagated to C++ + */ +open class HybridBaseSpec_cxx { + /** + * The Swift <> C++ bridge's namespace (`margelo::nitro::test::external::bridge::swift`) + * from `NitroTestExternal-Swift-Cxx-Bridge.hpp`. + * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift. + */ + public typealias bridge = margelo.nitro.test.external.bridge.swift + + /** + * Holds an instance of the `HybridBaseSpec` Swift protocol. + */ + private var __implementation: any HybridBaseSpec + + /** + * Holds a weak pointer to the C++ class that wraps the Swift class. + */ + private var __cxxPart: bridge.std__weak_ptr_HybridBaseSpec_ + + /** + * Create a new `HybridBaseSpec_cxx` that wraps the given `HybridBaseSpec`. + * All properties and methods bridge to C++ types. + */ + public init(_ implementation: any HybridBaseSpec) { + self.__implementation = implementation + self.__cxxPart = .init() + /* no base class */ + } + + /** + * Get the actual `HybridBaseSpec` instance this class wraps. + */ + @inline(__always) + public func getHybridBaseSpec() -> any HybridBaseSpec { + return __implementation + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `HybridBaseSpec_cxx`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridBaseSpec_cxx { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } + + /** + * Gets (or creates) the C++ part of this Hybrid Object. + * The C++ part is a `std::shared_ptr`. + */ + public func getCxxPart() -> bridge.std__shared_ptr_HybridBaseSpec_ { + let cachedCxxPart = self.__cxxPart.lock() + if Bool(fromCxx: cachedCxxPart) { + return cachedCxxPart + } else { + let newCxxPart = bridge.create_std__shared_ptr_HybridBaseSpec_(self.toUnsafe()) + __cxxPart = bridge.weakify_std__shared_ptr_HybridBaseSpec_(newCxxPart) + return newCxxPart + } + } + + + + /** + * Get the memory size of the Swift class (plus size of any other allocations) + * so the JS VM can properly track it and garbage-collect the JS object if needed. + */ + @inline(__always) + public var memorySize: Int { + return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize + } + + /** + * Compares this object with the given [other] object for reference equality. + */ + @inline(__always) + public func equals(other: HybridBaseSpec_cxx) -> Bool { + return self.__implementation === other.__implementation + } + + /** + * Call dispose() on the Swift class. + * This _may_ be called manually from JS. + */ + @inline(__always) + public func dispose() { + self.__implementation.dispose() + } + + /** + * Call toString() on the Swift class. + */ + @inline(__always) + public func toString() -> String { + return self.__implementation.toString() + } + + // Properties + public final var baseValue: Double { + @inline(__always) + get { + return self.__implementation.baseValue + } + } + + // Methods + +} diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/shared/c++/HybridBaseSpec.cpp b/packages/react-native-nitro-test-external/nitrogen/generated/shared/c++/HybridBaseSpec.cpp new file mode 100644 index 000000000..1d2b83e65 --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/shared/c++/HybridBaseSpec.cpp @@ -0,0 +1,21 @@ +/// +/// HybridBaseSpec.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include "HybridBaseSpec.hpp" + +namespace margelo::nitro::test::external { + + void HybridBaseSpec::loadHybridMethods() { + // load base methods/properties + HybridObject::loadHybridMethods(); + // load custom methods/properties + registerHybrids(this, [](Prototype& prototype) { + prototype.registerHybridGetter("baseValue", &HybridBaseSpec::getBaseValue); + }); + } + +} // namespace margelo::nitro::test::external diff --git a/packages/react-native-nitro-test-external/nitrogen/generated/shared/c++/HybridBaseSpec.hpp b/packages/react-native-nitro-test-external/nitrogen/generated/shared/c++/HybridBaseSpec.hpp new file mode 100644 index 000000000..b858e6e1c --- /dev/null +++ b/packages/react-native-nitro-test-external/nitrogen/generated/shared/c++/HybridBaseSpec.hpp @@ -0,0 +1,62 @@ +/// +/// HybridBaseSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#if __has_include() +#include +#else +#error NitroModules cannot be found! Are you sure you installed NitroModules properly? +#endif + + + + + +namespace margelo::nitro::test::external { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Base` + * Inherit this class to create instances of `HybridBaseSpec` in C++. + * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. + * @example + * ```cpp + * class HybridBase: public HybridBaseSpec { + * public: + * HybridBase(...): HybridObject(TAG) { ... } + * // ... + * }; + * ``` + */ + class HybridBaseSpec: public virtual HybridObject { + public: + // Constructor + explicit HybridBaseSpec(): HybridObject(TAG) { } + + // Destructor + ~HybridBaseSpec() override = default; + + public: + // Properties + virtual double getBaseValue() = 0; + + public: + // Methods + + + protected: + // Hybrid Setup + void loadHybridMethods() override; + + protected: + // Tag for logging + static constexpr auto TAG = "Base"; + }; + +} // namespace margelo::nitro::test::external diff --git a/packages/react-native-nitro-test-external/src/specs/SomeExternalObject.nitro.ts b/packages/react-native-nitro-test-external/src/specs/SomeExternalObject.nitro.ts index fbf3a0a9b..b0803d432 100644 --- a/packages/react-native-nitro-test-external/src/specs/SomeExternalObject.nitro.ts +++ b/packages/react-native-nitro-test-external/src/specs/SomeExternalObject.nitro.ts @@ -28,3 +28,9 @@ export interface SomeExternalObject optionalInt64?: Int64 ): OptionalPrimitivesHolder } + +// This is a simple `HybridObject` with just one value. +export interface Base + extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { + readonly baseValue: number +}