diff --git a/javascript/sources/Node.cc b/javascript/sources/Node.cc index 2268c805..748a6cd0 100644 --- a/javascript/sources/Node.cc +++ b/javascript/sources/Node.cc @@ -53,6 +53,7 @@ static void globalDirtiedFunc(YGNodeRef nodeRef) Node::Node(Config * config) : m_node(config != nullptr ? YGNodeNewWithConfig(config->m_config) : YGNodeNew()) , m_measureFunc(nullptr) +, m_dirtiedFunc(nullptr) { YGNodeSetContext(m_node, reinterpret_cast(this)); } @@ -65,6 +66,7 @@ Node::~Node(void) void Node::reset(void) { m_measureFunc.reset(nullptr); + m_dirtiedFunc.reset(nullptr); YGNodeReset(m_node); } diff --git a/javascript/tests/Facebook.Yoga/YGDirtiedTest.js b/javascript/tests/Facebook.Yoga/YGDirtiedTest.js index 460a04c4..20320c43 100644 --- a/javascript/tests/Facebook.Yoga/YGDirtiedTest.js +++ b/javascript/tests/Facebook.Yoga/YGDirtiedTest.js @@ -124,3 +124,45 @@ it("dirtied_hierarchy", function() { typeof gc !== "undefined" && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); + +it("dirtied_reset", function() { + var root = Yoga.Node.create(); + root.setAlignItems(Yoga.ALIGN_FLEX_START); + root.setWidth(100); + root.setHeight(100); + root.setMeasureFunc(function() {}); + + root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); + + let dirtied = 0; + root.setDirtiedFunc(function() { + dirtied++; + }); + + console.assert(0 === dirtied, "0 === dirtied"); + + // dirtied func MUST be called in case of explicit dirtying. + root.markDirty(); + console.assert(1 === dirtied, "1 === dirtied"); + + // recalculate so the root is no longer dirty + root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); + + root.reset(); + root.setAlignItems(Yoga.ALIGN_FLEX_START); + root.setWidth(100); + root.setHeight(100); + root.setMeasureFunc(function() {}); + + root.markDirty(); + + // dirtied func must NOT be called after reset. + root.markDirty(); + console.assert(1 === dirtied, "1 === dirtied"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + typeof gc !== "undefined" && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +});