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:
+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
|
||||
Reference in New Issue
Block a user