Skip to content

Commit

Permalink
Ensure child layouts mark dirty when flex direction changes
Browse files Browse the repository at this point in the history
There is some odd behavior when changing flexDirection values (row/column/etc). For example, when "Fill" scale type is being used, child layouts can become completely collapsed when the parent's flexDirection changes.

The heart of the issue was that since we compute things like flexGrow/Shrink and align values in syncStyle based on the parent's flexDirection (before passing them into the layout engine), when a parent layout's flexDirection changes, we need to mark it's direct layout children dirty so syncStyle will be reapplied on them (which includes LayoutComponents and NestedArtboardLayouts).

https://github.com/user-attachments/assets/2bb130a8-ecf2-46cb-a810-87fe135bbc0a

Diffs=
1be9b574d1 Ensure child layouts mark dirty when flex direction changes (#8792)

Co-authored-by: Philip Chung <[email protected]>
  • Loading branch information
philter and philter committed Dec 21, 2024
1 parent b0a72f3 commit e120f16
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4f4e07a68b9e9979532fcc932ced558f3f8e1047
1be9b574d145a1a1d7a32ed57416eb104af12986
1 change: 1 addition & 0 deletions include/rive/layout_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class LayoutComponent : public LayoutComponentBase,
void positionTypeChanged();
void scaleTypeChanged();
void displayChanged();
void flexDirectionChanged();
#endif
void buildDependencies() override;

Expand Down
1 change: 1 addition & 0 deletions include/rive/nested_artboard_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class NestedArtboardLayout : public NestedArtboardLayoutBase
#endif
Core* clone() const override;
void markNestedLayoutDirty();
void markLayoutNodeDirty();
void update(ComponentDirt value) override;
StatusCode onAddedClean(CoreContext* context) override;

Expand Down
13 changes: 9 additions & 4 deletions src/layout/layout_component_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ void LayoutComponentStyle::displayChanged()
}
}

void LayoutComponentStyle::flexDirectionValueChanged()
{
if (parent()->is<LayoutComponent>())
{
parent()->as<LayoutComponent>()->flexDirectionChanged();
}
}

StatusCode LayoutComponentStyle::onAddedDirty(CoreContext* context)
{
auto code = Super::onAddedDirty(context);
Expand All @@ -257,6 +265,7 @@ void LayoutComponentStyle::markLayoutNodeDirty() {}
void LayoutComponentStyle::markLayoutStyleDirty() {}
void LayoutComponentStyle::scaleTypeChanged() {}
void LayoutComponentStyle::displayChanged() {}
void LayoutComponentStyle::flexDirectionValueChanged() {}
#endif

void LayoutComponentStyle::interpolationTimeChanged() { markLayoutNodeDirty(); }
Expand All @@ -276,10 +285,6 @@ void LayoutComponentStyle::intrinsicallySizedValueChanged()
{
markLayoutNodeDirty();
}
void LayoutComponentStyle::flexDirectionValueChanged()
{
markLayoutNodeDirty();
}
void LayoutComponentStyle::directionValueChanged() { markLayoutNodeDirty(); }
void LayoutComponentStyle::alignContentValueChanged() { markLayoutNodeDirty(); }
void LayoutComponentStyle::alignItemsValueChanged() { markLayoutNodeDirty(); }
Expand Down
16 changes: 16 additions & 0 deletions src/layout_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,22 @@ void LayoutComponent::displayChanged()
m_displayChanged = true;
markLayoutNodeDirty();
}

void LayoutComponent::flexDirectionChanged()
{
markLayoutNodeDirty();
for (Component* child : children())
{
if (child->is<LayoutComponent>())
{
child->as<LayoutComponent>()->markLayoutNodeDirty();
}
else if (child->is<NestedArtboardLayout>())
{
child->as<NestedArtboardLayout>()->markLayoutNodeDirty();
}
}
}
#else
LayoutComponent::LayoutComponent() :
m_layoutData(new LayoutData()), m_proxy(this)
Expand Down
6 changes: 6 additions & 0 deletions src/nested_artboard_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ void NestedArtboardLayout::markNestedLayoutDirty()
}
}

void NestedArtboardLayout::markLayoutNodeDirty()
{
updateWidthOverride();
updateHeightOverride();
}

void NestedArtboardLayout::update(ComponentDirt value)
{
Super::update(value);
Expand Down

0 comments on commit e120f16

Please sign in to comment.