Skip to content

Commit

Permalink
fix: Use default value and register View!
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 15, 2025
1 parent c6ba220 commit 19b6b9a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/nitrogen/src/views/ViewComponentShadowNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ namespace ${namespace} {
for (const prop of spec.properties) {
propInitializers.push(
`
/* ${prop.name} */ ${escapeCppName(prop.name)}([&](){
/* ${prop.name} */ ${escapeCppName(prop.name)}([&]() -> ${prop.type.getCode('c++')} {
const react::RawValue* rawValue = rawProps.at("${prop.name}", nullptr, nullptr);
if (rawValue == nullptr) { ${prop.type.kind === 'optional' ? 'return nullptr;' : `throw std::runtime_error("${spec.name}: Prop \\"${prop.name}\\" is required and cannot be undefined!");`} }
if (rawValue == nullptr) { return {}; }
const auto& [runtime, value] = (std::pair<jsi::Runtime*, const jsi::Value&>)*rawValue;
return JSIConverter<${prop.type.getCode('c++')}>::fromJSI(*runtime, value);
}())`.trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ using namespace facebook;
+ (void) load {
[super load];
// TODO: Register it!
[RCTComponentViewFactory.currentComponentViewFactory registerComponentViewClass:[${component} class]];
}
+ (react::ComponentDescriptorProvider) componentDescriptorProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @implementation HybridTestViewComponent

+ (void) load {
[super load];
// TODO: Register it!
[RCTComponentViewFactory.currentComponentViewFactory registerComponentViewClass:[HybridTestViewComponent class]];
}

+ (react::ComponentDescriptorProvider) componentDescriptorProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ namespace margelo::nitro::image::views {
const HybridTestViewProps& sourceProps,
const react::RawProps& rawProps):
react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
/* someProp */ someProp([&](){
/* someProp */ someProp([&]() -> bool {
const react::RawValue* rawValue = rawProps.at("someProp", nullptr, nullptr);
if (rawValue == nullptr) { throw std::runtime_error("TestView: Prop \"someProp\" is required and cannot be undefined!"); }
if (rawValue == nullptr) { return {}; }
const auto& [runtime, value] = (std::pair<jsi::Runtime*, const jsi::Value&>)*rawValue;
return JSIConverter<bool>::fromJSI(*runtime, value);
}()),
/* someCallback */ someCallback([&](){
/* someCallback */ someCallback([&]() -> std::function<void(double /* someParam */)> {
const react::RawValue* rawValue = rawProps.at("someCallback", nullptr, nullptr);
if (rawValue == nullptr) { throw std::runtime_error("TestView: Prop \"someCallback\" is required and cannot be undefined!"); }
if (rawValue == nullptr) { return {}; }
const auto& [runtime, value] = (std::pair<jsi::Runtime*, const jsi::Value&>)*rawValue;
return JSIConverter<std::function<void(double /* someParam */)>>::fromJSI(*runtime, value);
}()) {
Expand Down

0 comments on commit 19b6b9a

Please sign in to comment.