editor+runtime: fix slow hit-testing turns out forEachChild + recursion is a bad combo. Recurse on just the first level of the hierarchy. I also made sure that the `forEachChild` in both Dart and C++ would do the same thing, and have the same signature. Diffs= 90da85fbb4 editor+runtime: fix slow hit-testing (#8907) Co-authored-by: Susan Wang <susan@rive.app>
diff --git a/.rive_head b/.rive_head index fb10e0b..6dd81aa 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -b03d365c93d0d52f0f05ae598deacbf7dd330a53 +90da85fbb4151a7a4a1c30cf2f6738929debe925
diff --git a/include/rive/container_component.hpp b/include/rive/container_component.hpp index 04cf246..7fd590e 100644 --- a/include/rive/container_component.hpp +++ b/include/rive/container_component.hpp
@@ -13,10 +13,12 @@ virtual void addChild(Component* component); bool collapse(bool value) override; - // Returns true if it searched through all of its children. predicate can - // return false to stop searching. + // Returns whether predicate returns true for the current Component. bool forAll(std::function<bool(Component*)> predicate); - bool forEachChild(std::function<bool(Component*)> predicate); + + // Recursively descend onto all the children in the hierarchy tree. + // If predicate returns false, it won't recurse down a particular branch. + void forEachChild(std::function<bool(Component*)> predicate); private: std::vector<Component*> m_children;
diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp index 6149b92..8d02ee3 100644 --- a/src/animation/state_machine_instance.cpp +++ b/src/animation/state_machine_instance.cpp
@@ -1220,7 +1220,7 @@ hitLookup, listenerGroup, isOpaque); - return true; + return false; }); return; }
diff --git a/src/container_component.cpp b/src/container_component.cpp index a018b2e..4808c36 100644 --- a/src/container_component.cpp +++ b/src/container_component.cpp
@@ -29,19 +29,17 @@ return true; } -bool ContainerComponent::forEachChild(std::function<bool(Component*)> predicate) +void ContainerComponent::forEachChild(std::function<bool(Component*)> predicate) { for (Component* child : m_children) { if (!predicate(child)) { - return false; + continue; } - if (child->is<ContainerComponent>() && - !child->as<ContainerComponent>()->forEachChild(predicate)) + if (child->is<ContainerComponent>()) { - return false; + child->as<ContainerComponent>()->forEachChild(predicate); } } - return true; } \ No newline at end of file