mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
Init using create-nitro-module
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
///
|
||||
/// HybridOmniSpec.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.omni
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.facebook.jni.HybridData
|
||||
import com.facebook.proguard.annotations.DoNotStrip
|
||||
import com.margelo.nitro.core.HybridObject
|
||||
import com.margelo.nitro.views.HybridView
|
||||
|
||||
/**
|
||||
* A Kotlin class representing the Omni HybridObject.
|
||||
* Implement this abstract class to create Kotlin-based instances of Omni.
|
||||
*/
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
@Suppress(
|
||||
"KotlinJniMissingFunction", "unused",
|
||||
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
||||
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
||||
)
|
||||
abstract class HybridOmniSpec: HybridView() {
|
||||
// Properties
|
||||
@get:DoNotStrip
|
||||
@get:Keep
|
||||
@set:DoNotStrip
|
||||
@set:Keep
|
||||
abstract var isRed: Boolean
|
||||
|
||||
// Methods
|
||||
|
||||
|
||||
// Default implementation of `HybridObject.toString()`
|
||||
override fun toString(): String {
|
||||
return "[HybridObject Omni]"
|
||||
}
|
||||
|
||||
// C++ backing class
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
protected open class CxxPart(javaPart: HybridOmniSpec): HybridObject.CxxPart(javaPart) {
|
||||
// C++ JHybridOmniSpec::CxxPart::initHybrid(...)
|
||||
external override fun initHybrid(): HybridData
|
||||
}
|
||||
override fun createCxxPart(): CxxPart {
|
||||
return CxxPart(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
protected const val TAG = "HybridOmniSpec"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
///
|
||||
/// OmniOnLoad.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.omni
|
||||
|
||||
import android.util.Log
|
||||
|
||||
internal class OmniOnLoad {
|
||||
companion object {
|
||||
private const val TAG = "OmniOnLoad"
|
||||
private var didLoad = false
|
||||
/**
|
||||
* Initializes the native part of "Omni".
|
||||
* This method is idempotent and can be called more than once.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun initializeNative() {
|
||||
if (didLoad) return
|
||||
try {
|
||||
Log.i(TAG, "Loading Omni C++ library...")
|
||||
System.loadLibrary("Omni")
|
||||
Log.i(TAG, "Successfully loaded Omni C++ library!")
|
||||
didLoad = true
|
||||
} catch (e: Error) {
|
||||
Log.e(TAG, "Failed to load Omni C++ library! Is it properly installed and linked? " +
|
||||
"Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
///
|
||||
/// HybridOmniManager.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.omni.views
|
||||
|
||||
import android.view.View
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap
|
||||
import com.facebook.react.uimanager.SimpleViewManager
|
||||
import com.facebook.react.uimanager.StateWrapper
|
||||
import com.facebook.react.uimanager.ThemedReactContext
|
||||
import com.margelo.nitro.R.id.associated_hybrid_view_tag
|
||||
import com.margelo.nitro.views.RecyclableView
|
||||
import com.omni.*
|
||||
|
||||
/**
|
||||
* Represents the React Native `ViewManager` for the "Omni" Nitro HybridView.
|
||||
*/
|
||||
public class HybridOmniManager: SimpleViewManager<View>() {
|
||||
init {
|
||||
if (RecyclableView::class.java.isAssignableFrom(HybridOmni::class.java)) {
|
||||
// Enable view recycling
|
||||
super.setupViewRecycling()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return "Omni"
|
||||
}
|
||||
|
||||
override fun createViewInstance(reactContext: ThemedReactContext): View {
|
||||
val hybridView = HybridOmni(reactContext)
|
||||
val view = hybridView.view
|
||||
view.setTag(associated_hybrid_view_tag, hybridView)
|
||||
return view
|
||||
}
|
||||
|
||||
override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any? {
|
||||
val hybridView = getHybridView(view)
|
||||
?: throw Error("Couldn't find view $view in local views table!")
|
||||
|
||||
// 1. Update each prop individually
|
||||
hybridView.beforeUpdate()
|
||||
HybridOmniStateUpdater.updateViewProps(hybridView, stateWrapper)
|
||||
hybridView.afterUpdate()
|
||||
|
||||
// 2. Continue in base View props
|
||||
return super.updateState(view, props, stateWrapper)
|
||||
}
|
||||
|
||||
override fun onDropViewInstance(view: View) {
|
||||
val hybridView = getHybridView(view)
|
||||
hybridView?.onDropView()
|
||||
return super.onDropViewInstance(view)
|
||||
}
|
||||
|
||||
protected override fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? {
|
||||
super.prepareToRecycleView(reactContext, view)
|
||||
val hybridView = getHybridView(view)
|
||||
?: return null
|
||||
|
||||
@Suppress("USELESS_IS_CHECK")
|
||||
if (hybridView is RecyclableView) {
|
||||
// Recycle in it's implementation
|
||||
hybridView.prepareForRecycle()
|
||||
|
||||
// Maybe update the view if it changed
|
||||
return hybridView.view
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getHybridView(view: View): HybridOmni? {
|
||||
return view.getTag(associated_hybrid_view_tag) as? HybridOmni
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
///
|
||||
/// HybridOmniStateUpdater.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.omni.views
|
||||
|
||||
import com.facebook.react.uimanager.StateWrapper
|
||||
import com.margelo.nitro.omni.*
|
||||
|
||||
internal class HybridOmniStateUpdater {
|
||||
companion object {
|
||||
/**
|
||||
* Updates the props for [view] through C++.
|
||||
* The [state] prop is expected to contain [view]'s props as wrapped Fabric state.
|
||||
*/
|
||||
@Suppress("KotlinJniMissingFunction")
|
||||
@JvmStatic
|
||||
external fun updateViewProps(view: HybridOmniSpec, state: StateWrapper)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user