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