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:
+83
@@ -0,0 +1,83 @@
|
||||
#
|
||||
# Omni+autolinking.cmake
|
||||
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
# https://github.com/mrousavy/nitro
|
||||
# Copyright © Marc Rousavy @ Margelo
|
||||
#
|
||||
|
||||
# This is a CMake file that adds all files generated by Nitrogen
|
||||
# to the current CMake project.
|
||||
#
|
||||
# To use it, add this to your CMakeLists.txt:
|
||||
# ```cmake
|
||||
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/Omni+autolinking.cmake)
|
||||
# ```
|
||||
|
||||
# Define a flag to check if we are building properly
|
||||
add_definitions(-DBUILDING_OMNI_WITH_GENERATED_CMAKE_PROJECT)
|
||||
|
||||
# Enable Raw Props parsing in react-native (for Nitro Views)
|
||||
add_definitions(-DRN_SERIALIZABLE_STATE)
|
||||
|
||||
# Add all headers that were generated by Nitrogen
|
||||
include_directories(
|
||||
"../nitrogen/generated/shared/c++"
|
||||
"../nitrogen/generated/android/c++"
|
||||
"../nitrogen/generated/android/"
|
||||
)
|
||||
|
||||
# Add all .cpp sources that were generated by Nitrogen
|
||||
target_sources(
|
||||
# CMake project name (Android C++ library name)
|
||||
Omni PRIVATE
|
||||
# Autolinking Setup
|
||||
../nitrogen/generated/android/OmniOnLoad.cpp
|
||||
# Shared Nitrogen C++ sources
|
||||
../nitrogen/generated/shared/c++/HybridOmniSpec.cpp
|
||||
../nitrogen/generated/shared/c++/views/HybridOmniComponent.cpp
|
||||
# Android-specific Nitrogen C++ sources
|
||||
../nitrogen/generated/android/c++/JHybridOmniSpec.cpp
|
||||
../nitrogen/generated/android/c++/views/JHybridOmniStateUpdater.cpp
|
||||
)
|
||||
|
||||
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
||||
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
||||
target_compile_definitions(
|
||||
Omni PRIVATE
|
||||
-DFOLLY_NO_CONFIG=1
|
||||
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
||||
-DFOLLY_USE_LIBCPP=1
|
||||
-DFOLLY_CFG_NO_COROUTINES=1
|
||||
-DFOLLY_MOBILE=1
|
||||
-DFOLLY_HAVE_RECVMMSG=1
|
||||
-DFOLLY_HAVE_PTHREAD=1
|
||||
# Once we target android-23 above, we can comment
|
||||
# the following line. NDK uses GNU style stderror_r() after API 23.
|
||||
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
||||
)
|
||||
|
||||
# Add all libraries required by the generated specs
|
||||
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
||||
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
||||
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
||||
|
||||
# Link all libraries together
|
||||
target_link_libraries(
|
||||
Omni
|
||||
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
||||
ReactAndroid::jsi # <-- RN: JSI
|
||||
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
||||
)
|
||||
|
||||
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
||||
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
||||
target_link_libraries(
|
||||
Omni
|
||||
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
||||
)
|
||||
else()
|
||||
target_link_libraries(
|
||||
Omni
|
||||
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
||||
)
|
||||
endif()
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
///
|
||||
/// Omni+autolinking.gradle
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
/// This is a Gradle file that adds all files generated by Nitrogen
|
||||
/// to the current Gradle project.
|
||||
///
|
||||
/// To use it, add this to your build.gradle:
|
||||
/// ```gradle
|
||||
/// apply from: '../nitrogen/generated/android/Omni+autolinking.gradle'
|
||||
/// ```
|
||||
|
||||
logger.warn("[NitroModules] 🔥 Omni is boosted by nitro!")
|
||||
|
||||
android {
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs += [
|
||||
// Nitrogen files
|
||||
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
///
|
||||
/// OmniOnLoad.cpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#ifndef BUILDING_OMNI_WITH_GENERATED_CMAKE_PROJECT
|
||||
#error OmniOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
||||
#endif
|
||||
|
||||
#include "OmniOnLoad.hpp"
|
||||
|
||||
#include <jni.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <NitroModules/HybridObjectRegistry.hpp>
|
||||
|
||||
#include "JHybridOmniSpec.hpp"
|
||||
#include "views/JHybridOmniStateUpdater.hpp"
|
||||
#include <NitroModules/DefaultConstructableObject.hpp>
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
int initialize(JavaVM* vm) {
|
||||
return facebook::jni::initialize(vm, []() {
|
||||
::margelo::nitro::omni::registerAllNatives();
|
||||
});
|
||||
}
|
||||
|
||||
struct JHybridOmniSpecImpl: public jni::JavaClass<JHybridOmniSpecImpl, JHybridOmniSpec::JavaPart> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/omni/HybridOmni;";
|
||||
static std::shared_ptr<JHybridOmniSpec> create() {
|
||||
static const auto constructorFn = javaClassStatic()->getConstructor<JHybridOmniSpecImpl::javaobject()>();
|
||||
jni::local_ref<JHybridOmniSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
||||
return javaPart->getJHybridOmniSpec();
|
||||
}
|
||||
};
|
||||
|
||||
void registerAllNatives() {
|
||||
using namespace margelo::nitro;
|
||||
using namespace margelo::nitro::omni;
|
||||
|
||||
// Register native JNI methods
|
||||
margelo::nitro::omni::JHybridOmniSpec::CxxPart::registerNatives();
|
||||
margelo::nitro::omni::views::JHybridOmniStateUpdater::registerNatives();
|
||||
|
||||
// Register Nitro Hybrid Objects
|
||||
HybridObjectRegistry::registerHybridObjectConstructor(
|
||||
"Omni",
|
||||
[]() -> std::shared_ptr<HybridObject> {
|
||||
return JHybridOmniSpecImpl::create();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
///
|
||||
/// OmniOnLoad.hpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#include <jni.h>
|
||||
#include <functional>
|
||||
#include <NitroModules/NitroDefines.hpp>
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
[[deprecated("Use registerNatives() instead.")]]
|
||||
int initialize(JavaVM* vm);
|
||||
|
||||
/**
|
||||
* Register the native (C++) part of Omni, and autolinks all Hybrid Objects.
|
||||
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
||||
* inside a `facebook::jni::initialize(vm, ...)` call.
|
||||
* Example:
|
||||
* ```cpp (cpp-adapter.cpp)
|
||||
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
||||
* return facebook::jni::initialize(vm, []() {
|
||||
* // register all Omni HybridObjects
|
||||
* margelo::nitro::omni::registerNatives();
|
||||
* // any other custom registrations go here.
|
||||
* });
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
void registerAllNatives();
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
///
|
||||
/// JHybridOmniSpec.cpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#include "JHybridOmniSpec.hpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
std::shared_ptr<JHybridOmniSpec> JHybridOmniSpec::JavaPart::getJHybridOmniSpec() {
|
||||
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
||||
auto castHybridObject = std::dynamic_pointer_cast<JHybridOmniSpec>(hybridObject);
|
||||
if (castHybridObject == nullptr) [[unlikely]] {
|
||||
throw std::runtime_error("Failed to downcast JHybridObject to JHybridOmniSpec!");
|
||||
}
|
||||
return castHybridObject;
|
||||
}
|
||||
|
||||
jni::local_ref<JHybridOmniSpec::CxxPart::jhybriddata> JHybridOmniSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
||||
return makeCxxInstance(jThis);
|
||||
}
|
||||
|
||||
std::shared_ptr<JHybridObject> JHybridOmniSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
||||
auto castJavaPart = jni::dynamic_ref_cast<JHybridOmniSpec::JavaPart>(javaPart);
|
||||
if (castJavaPart == nullptr) [[unlikely]] {
|
||||
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridOmniSpec::JavaPart!");
|
||||
}
|
||||
return std::make_shared<JHybridOmniSpec>(castJavaPart);
|
||||
}
|
||||
|
||||
void JHybridOmniSpec::CxxPart::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", JHybridOmniSpec::CxxPart::initHybrid),
|
||||
});
|
||||
}
|
||||
|
||||
// Properties
|
||||
bool JHybridOmniSpec::getIsRed() {
|
||||
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isRed");
|
||||
auto __result = method(_javaPart);
|
||||
return static_cast<bool>(__result);
|
||||
}
|
||||
void JHybridOmniSpec::setIsRed(bool isRed) {
|
||||
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* isRed */)>("setRed");
|
||||
method(_javaPart, isRed);
|
||||
}
|
||||
|
||||
// Methods
|
||||
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
///
|
||||
/// HybridOmniSpec.hpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NitroModules/JHybridObject.hpp>
|
||||
#include <fbjni/fbjni.h>
|
||||
#include "HybridOmniSpec.hpp"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
class JHybridOmniSpec: public virtual HybridOmniSpec, public virtual JHybridObject {
|
||||
public:
|
||||
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/HybridOmniSpec;";
|
||||
std::shared_ptr<JHybridOmniSpec> getJHybridOmniSpec();
|
||||
};
|
||||
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/HybridOmniSpec$CxxPart;";
|
||||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
||||
static void registerNatives();
|
||||
using HybridBase::HybridBase;
|
||||
protected:
|
||||
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit JHybridOmniSpec(const jni::local_ref<JHybridOmniSpec::JavaPart>& javaPart):
|
||||
HybridObject(HybridOmniSpec::TAG),
|
||||
JHybridObject(javaPart),
|
||||
_javaPart(jni::make_global(javaPart)) {}
|
||||
~JHybridOmniSpec() override {
|
||||
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
||||
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
||||
}
|
||||
|
||||
public:
|
||||
inline const jni::global_ref<JHybridOmniSpec::JavaPart>& getJavaPart() const noexcept {
|
||||
return _javaPart;
|
||||
}
|
||||
|
||||
public:
|
||||
// Properties
|
||||
bool getIsRed() override;
|
||||
void setIsRed(bool isRed) override;
|
||||
|
||||
public:
|
||||
// Methods
|
||||
|
||||
|
||||
private:
|
||||
jni::global_ref<JHybridOmniSpec::JavaPart> _javaPart;
|
||||
};
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
@@ -0,0 +1,56 @@
|
||||
///
|
||||
/// JHybridOmniStateUpdater.cpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#include "JHybridOmniStateUpdater.hpp"
|
||||
#include "views/HybridOmniComponent.hpp"
|
||||
#include <NitroModules/NitroDefines.hpp>
|
||||
#include <react/fabric/StateWrapperImpl.h>
|
||||
|
||||
namespace margelo::nitro::omni::views {
|
||||
|
||||
using namespace facebook;
|
||||
using ConcreteStateData = react::ConcreteState<HybridOmniState>;
|
||||
|
||||
void JHybridOmniStateUpdater::updateViewProps(jni::alias_ref<jni::JClass> /* class */,
|
||||
jni::alias_ref<JHybridOmniSpec::JavaPart> javaView,
|
||||
jni::alias_ref<JStateWrapper::javaobject> stateWrapperInterface) {
|
||||
std::shared_ptr<JHybridOmniSpec> hybridView = javaView->getJHybridOmniSpec();
|
||||
|
||||
// Get concrete StateWrapperImpl from passed StateWrapper interface object
|
||||
jobject rawStateWrapper = stateWrapperInterface.get();
|
||||
if (!stateWrapperInterface->isInstanceOf(react::StateWrapperImpl::javaClassStatic())) [[unlikely]] {
|
||||
throw std::runtime_error("StateWrapper is not a StateWrapperImpl");
|
||||
}
|
||||
auto stateWrapper = jni::alias_ref<react::StateWrapperImpl::javaobject>{
|
||||
static_cast<react::StateWrapperImpl::javaobject>(rawStateWrapper)};
|
||||
std::shared_ptr<const react::State> state = stateWrapper->cthis()->getState();
|
||||
auto concreteState = std::static_pointer_cast<const ConcreteStateData>(state);
|
||||
const HybridOmniState& data = concreteState->getData();
|
||||
const std::shared_ptr<HybridOmniProps>& props = data.getProps();
|
||||
if (props == nullptr) [[unlikely]] {
|
||||
// Props aren't set yet!
|
||||
throw std::runtime_error("HybridOmniState's data doesn't contain any props!");
|
||||
}
|
||||
|
||||
// Update all props if they are dirty
|
||||
if (props->isRed.isDirty) {
|
||||
hybridView->setIsRed(props->isRed.value);
|
||||
props->isRed.isDirty = false;
|
||||
}
|
||||
|
||||
// Update hybridRef if it changed
|
||||
if (props->hybridRef.isDirty) {
|
||||
// hybridRef changed - call it with new this
|
||||
const auto& maybeFunc = props->hybridRef.value;
|
||||
if (maybeFunc.has_value()) {
|
||||
maybeFunc.value()(hybridView);
|
||||
}
|
||||
props->hybridRef.isDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace margelo::nitro::omni::views
|
||||
@@ -0,0 +1,49 @@
|
||||
///
|
||||
/// JHybridOmniStateUpdater.hpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef RN_SERIALIZABLE_STATE
|
||||
#error Omni was compiled without the 'RN_SERIALIZABLE_STATE' flag. This flag is required for Nitro Views - set it in your CMakeLists!
|
||||
#endif
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <react/fabric/CoreComponentsRegistry.h>
|
||||
#include <react/fabric/StateWrapperImpl.h>
|
||||
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
||||
#include <NitroModules/NitroDefines.hpp>
|
||||
#include <NitroModules/JStateWrapper.hpp>
|
||||
#include "JHybridOmniSpec.hpp"
|
||||
#include "views/HybridOmniComponent.hpp"
|
||||
|
||||
namespace margelo::nitro::omni::views {
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
class JHybridOmniStateUpdater final: public jni::JavaClass<JHybridOmniStateUpdater> {
|
||||
public:
|
||||
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/views/HybridOmniStateUpdater;";
|
||||
|
||||
public:
|
||||
static void updateViewProps(jni::alias_ref<jni::JClass> /* class */,
|
||||
jni::alias_ref<JHybridOmniSpec::JavaPart> view,
|
||||
jni::alias_ref<JStateWrapper::javaobject> stateWrapperInterface);
|
||||
|
||||
public:
|
||||
static void registerNatives() {
|
||||
// Register JNI calls
|
||||
javaClassStatic()->registerNatives({
|
||||
makeNativeMethod("updateViewProps", JHybridOmniStateUpdater::updateViewProps),
|
||||
});
|
||||
// Register React Native view component descriptor
|
||||
auto provider = react::concreteComponentDescriptorProvider<HybridOmniComponentDescriptor>();
|
||||
auto providerRegistry = react::CoreComponentsRegistry::sharedProviderRegistry();
|
||||
providerRegistry->add(provider);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace margelo::nitro::omni::views
|
||||
@@ -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