Skip to content

Commit

Permalink
fix: Properly downcast
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 16, 2025
1 parent 224925f commit 8fa40b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/nitrogen/src/views/swift/SwiftHybridViewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function createSwiftHybridViewManager(
return `
if (newViewProps.${name}.isDirty) {
swiftPart.${p.cppSetterName}(newViewProps.${name}.value);
newViewProps.${name}.isDirty = false;
}
`.trim()
})
Expand Down Expand Up @@ -103,7 +104,8 @@ using namespace ${namespace}::views;
- (void) updateProps:(const react::Props::Shared&)props
oldProps:(const react::Props::Shared&)oldProps {
// 1. Downcast props
const auto& newViewProps = *std::static_pointer_cast<${propsClassName} const>(props);
const auto& newViewPropsConst = *std::static_pointer_cast<${propsClassName} const>(props);
auto& newViewProps = const_cast<${propsClassName}&>(newViewPropsConst);
${swiftNamespace}::${HybridTSpecCxx}& swiftPart = _hybridView->getSwiftPart();
// 2. Update each prop
${indent(propAssignments.join('\n'), ' ')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ - (void) updateView {
- (void) updateProps:(const react::Props::Shared&)props
oldProps:(const react::Props::Shared&)oldProps {
// 1. Downcast props
const auto& newViewProps = *std::static_pointer_cast<HybridTestViewProps const>(props);
const auto& newViewPropsConst = *std::static_pointer_cast<HybridTestViewProps const>(props);
auto& newViewProps = const_cast<HybridTestViewProps&>(newViewPropsConst);
NitroImage::HybridTestViewSpec_cxx& swiftPart = _hybridView->getSwiftPart();
// 2. Update each prop
if (newViewProps.someProp.isDirty) {
swiftPart.setSomeProp(newViewProps.someProp.value);
newViewProps.someProp.isDirty = false;
}
if (newViewProps.someCallback.isDirty) {
swiftPart.setSomeCallback(newViewProps.someCallback.value);
newViewProps.someCallback.isDirty = false;
}
// 3. Continue in base class
[super updateProps:props oldProps:oldProps];
Expand Down

0 comments on commit 8fa40b2

Please sign in to comment.