diff --git a/packages/react-native-nitro-modules/android/src/main/java/com/margelo/nitro/views/HybridView.kt b/packages/react-native-nitro-modules/android/src/main/java/com/margelo/nitro/views/HybridView.kt new file mode 100644 index 000000000..c68abc4d3 --- /dev/null +++ b/packages/react-native-nitro-modules/android/src/main/java/com/margelo/nitro/views/HybridView.kt @@ -0,0 +1,36 @@ +package com.margelo.nitro.core + +import androidx.annotation.Keep +import com.facebook.jni.HybridData +import com.facebook.proguard.annotations.DoNotStrip + +/** + * A base class for all Kotlin-based Hybrid Views. + */ +@Keep +@DoNotStrip +abstract class HybridView: HybridObject { + /** + * Get the `UIView` this HybridView is holding. + * + * This value should not change during the lifetime of this `HybridView`. + */ + @get:DoNotStrip + @get:Keep + abstract val view: View + + /** + * Holds the native C++ instance. + * In `HybridView`, the C++ instance is a sub-class of `JHybridView`, such as one of it's specs. + * This is `null`, until `updateNative(..)` is called. + */ + private var mHybridData: HybridData? = null + + /** + * Must be called in the constructor of a subclass of `HybridObject`, to initialize the C++ + * `JHybridObject` with a subclass of it. + */ + override fun updateNative(hybridData: HybridData) { + mHybridData = hybridData + } +} diff --git a/packages/react-native-nitro-modules/ios/views/HybridView.swift b/packages/react-native-nitro-modules/ios/views/HybridView.swift new file mode 100644 index 000000000..e712f6839 --- /dev/null +++ b/packages/react-native-nitro-modules/ios/views/HybridView.swift @@ -0,0 +1,25 @@ +// +// HybridView.swift +// NitroModules +// +// Created by Marc Rousavy on 13.01.25. +// + +#if canImport(UIKit) + +import Foundation +import UIKit + +/** + * A base protocol for all Swift-based Hybrid Views. + */ +public protocol HybridView: HybridObject { + /** + * Get the ``UIView`` this HybridView is holding. + * + * This value should not change during the lifetime of this ``HybridView``. + */ + var view: UIView { get } +} + +#endif