-
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.
feat: Create
HybridView
Swift and Kotlin base
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...es/react-native-nitro-modules/android/src/main/java/com/margelo/nitro/views/HybridView.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,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
25
packages/react-native-nitro-modules/ios/views/HybridView.swift
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,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 |