Skip to content

Commit

Permalink
feat: Create HybridView Swift and Kotlin base
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 13, 2025
1 parent d5dd70c commit 71ae446
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
25 changes: 25 additions & 0 deletions packages/react-native-nitro-modules/ios/views/HybridView.swift
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 71ae446

Please sign in to comment.