add isCollapsed validation on nested artboard advance method If the nested artboard is collapsed (for example when it's under a solo) the advance method will return. This helps prevent unused animations or state machines from running when hidden. Diffs= 8f6b07395 add isCollapsed validation on nested artboard advance method (#6081) Co-authored-by: hernan <hernan@rive.app>
diff --git a/.rive_head b/.rive_head index 737da8c..cfd6bcc 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -c5cde614bdb0de792c0bb074185f6ff51b1ff954 +8f6b07395cd5a595cd8cb96b6692bc46bb5b8f28
diff --git a/src/nested_artboard.cpp b/src/nested_artboard.cpp index f4ab1c3..25bd218 100644 --- a/src/nested_artboard.cpp +++ b/src/nested_artboard.cpp
@@ -123,7 +123,7 @@ bool NestedArtboard::advance(float elapsedSeconds) { - if (m_Artboard == nullptr) + if (m_Artboard == nullptr || isCollapsed()) { return false; }
diff --git a/test/assets/solos_with_nested_artboards.riv b/test/assets/solos_with_nested_artboards.riv new file mode 100644 index 0000000..6c8e64b --- /dev/null +++ b/test/assets/solos_with_nested_artboards.riv Binary files differ
diff --git a/test/nested_artboard.cpp b/test/nested_artboard.cpp new file mode 100644 index 0000000..2ce4939 --- /dev/null +++ b/test/nested_artboard.cpp
@@ -0,0 +1,39 @@ +#include <rive/solo.hpp> +#include <rive/nested_artboard.hpp> +#include <rive/shapes/rectangle.hpp> +#include <rive/shapes/shape.hpp> +#include <rive/animation/state_machine_instance.hpp> +#include <rive/animation/nested_linear_animation.hpp> +#include <rive/animation/nested_state_machine.hpp> +#include "rive_file_reader.hpp" +#include "rive_testing.hpp" +#include <catch.hpp> +#include <cstdio> +#include <iostream> + +TEST_CASE("collapsed nested artboards do not advance", "[solo]") +{ + auto file = ReadRiveFile("../../test/assets/solos_with_nested_artboards.riv"); + + auto artboard = file->artboard("main-artboard")->instance(); + artboard->advance(0.0f); + auto solos = artboard->find<rive::Solo>(); + REQUIRE(solos.size() == 1); + auto stateMachine = artboard->stateMachineAt(0); + stateMachine->advanceAndApply(0.0f); + REQUIRE(stateMachine->needsAdvance() == true); + artboard->advance(0.75f); + // Testing whether the squares have moved in the artboard is an indirect way + // if checking whether the time of each artboard has advanced + // Unfortunately there is no way of accessing the time of the animations directly + auto redNestedArtboard = stateMachine->artboard()->find<rive::NestedArtboard>("red-artboard"); + auto redNestedArtboardArtboard = redNestedArtboard->artboard(); + auto movingShapes = redNestedArtboardArtboard->find<rive::Shape>(); + auto redRect = movingShapes.at(0); + REQUIRE(redRect->x() > 50); + auto greenNestedArtboard = stateMachine->artboard()->find<rive::NestedArtboard>("green-artboard"); + auto greenNestedArtboardArtboard = greenNestedArtboard->artboard(); + auto greenMovingShapes = greenNestedArtboardArtboard->find<rive::Shape>(); + auto greenRect = greenMovingShapes.at(0); + REQUIRE(greenRect->x() == 50); +} \ No newline at end of file