Skip to content

Commit

Permalink
feat: Add HybridView protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 8, 2025
1 parent e39bac6 commit 4b0ff8e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class HybridObject: ExtendableHybridClass {
*
* @example
* ```kotlin
* val memorySize: ULong
* override val memorySize: ULong
* get() {
* val imageSize = this.bitmap.bytesPerRow * this.bitmap.height
* return imageSize
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.margelo.nitro.views

import android.view.View
import androidx.annotation.Keep
import com.facebook.jni.HybridData
import com.facebook.proguard.annotations.DoNotStrip
import com.margelo.nitro.core.HybridObject

/**
* A base class for all Kotlin-based HybridViews.
*/
@Keep
@DoNotStrip
abstract class HybridView: HybridObject {
/**
* Get the view that this HybridView holds.
*
* @example
* ```kotlin
* override val view: View = ImageView()
* ```
*/
@get:DoNotStrip
@get:Keep
abstract val view: View
}
28 changes: 28 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,28 @@
//
// HybridView.swift
// NitroModules
//
// Created by Marc Rousavy on 23.07.24.
//

#if canImport(UIKit)

import Foundation
import UIKit

/**
* A base protocol for all Swift-based Hybrid Views.
*/
public protocol HybridView: HybridObjectSpec {
/**
* Get the view that this HybridView holds.
*
* @example
* ```swift
* let view: UIView = UIImageView()
* ```
*/
var view: UIView { get }
}

#endif

0 comments on commit 4b0ff8e

Please sign in to comment.