Allow to end markers early

Summary:
Adds the ability to `MarkerSection` to end the marker before it goes out of scope.

This unlocks two scenarios:
- reuse the data associated with a marker after ending it.
- end markers in the middle of a function without adding arbitrary blocks.

Reviewed By: SidharthGuglani

Differential Revision: D15837840

fbshipit-source-id: c0afaeeabd169c65189b5028be54ea7dac3e3b84
This commit is contained in:
David Aurelio
2019-06-15 10:15:49 -07:00
committed by Facebook Github Bot
parent 6b5bf570c8
commit a7e8aec3d9
2 changed files with 9 additions and 10 deletions

View File

@@ -4026,9 +4026,7 @@ void YGNodeCalculateLayoutWithContext(
#ifdef YG_ENABLE_EVENTS #ifdef YG_ENABLE_EVENTS
Event::publish<Event::LayoutPassStart>(node, {layoutContext}); Event::publish<Event::LayoutPassStart>(node, {layoutContext});
#endif #endif
// unique pointer to allow ending the marker early marker::MarkerSection<YGMarkerLayout> marker{node};
std::unique_ptr<marker::MarkerSection<YGMarkerLayout>> marker{
new marker::MarkerSection<YGMarkerLayout>{node}};
// Increment the generation count. This will force the recursive routine to // Increment the generation count. This will force the recursive routine to
// visit all dirty nodes at least once. Subsequent visits will be skipped if // visit all dirty nodes at least once. Subsequent visits will be skipped if
@@ -4087,7 +4085,7 @@ void YGNodeCalculateLayoutWithContext(
true, true,
"initial", "initial",
node->getConfig(), node->getConfig(),
marker->data, marker.data,
layoutContext)) { layoutContext)) {
node->setPosition( node->setPosition(
node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth); node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth);
@@ -4104,12 +4102,11 @@ void YGNodeCalculateLayoutWithContext(
#endif #endif
} }
#ifdef YG_ENABLE_EVENTS marker.end();
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &marker->data});
#endif
// end marker here #ifdef YG_ENABLE_EVENTS
marker = nullptr; Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &marker.data});
#endif
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we // We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
// aren't sure whether client's of yoga have gotten rid off this flag or not. // aren't sure whether client's of yoga have gotten rid off this flag or not.

View File

@@ -19,11 +19,13 @@ private:
public: public:
MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {} MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {}
~MarkerSection() { void end() {
if (endMarker_) { if (endMarker_) {
endMarker_(MarkerType, node_, markerData(&data), userData_); endMarker_(MarkerType, node_, markerData(&data), userData_);
endMarker_ = nullptr;
} }
} }
~MarkerSection() { end(); }
typename Data::type data = {}; typename Data::type data = {};