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:
committed by
Facebook Github Bot
parent
6b5bf570c8
commit
a7e8aec3d9
@@ -4026,9 +4026,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
#ifdef YG_ENABLE_EVENTS
|
||||
Event::publish<Event::LayoutPassStart>(node, {layoutContext});
|
||||
#endif
|
||||
// unique pointer to allow ending the marker early
|
||||
std::unique_ptr<marker::MarkerSection<YGMarkerLayout>> marker{
|
||||
new marker::MarkerSection<YGMarkerLayout>{node}};
|
||||
marker::MarkerSection<YGMarkerLayout> marker{node};
|
||||
|
||||
// Increment the generation count. This will force the recursive routine to
|
||||
// visit all dirty nodes at least once. Subsequent visits will be skipped if
|
||||
@@ -4087,7 +4085,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
true,
|
||||
"initial",
|
||||
node->getConfig(),
|
||||
marker->data,
|
||||
marker.data,
|
||||
layoutContext)) {
|
||||
node->setPosition(
|
||||
node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth);
|
||||
@@ -4104,12 +4102,11 @@ void YGNodeCalculateLayoutWithContext(
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef YG_ENABLE_EVENTS
|
||||
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &marker->data});
|
||||
#endif
|
||||
marker.end();
|
||||
|
||||
// end marker here
|
||||
marker = nullptr;
|
||||
#ifdef YG_ENABLE_EVENTS
|
||||
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &marker.data});
|
||||
#endif
|
||||
|
||||
// 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.
|
||||
|
@@ -19,11 +19,13 @@ private:
|
||||
|
||||
public:
|
||||
MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {}
|
||||
~MarkerSection() {
|
||||
void end() {
|
||||
if (endMarker_) {
|
||||
endMarker_(MarkerType, node_, markerData(&data), userData_);
|
||||
endMarker_ = nullptr;
|
||||
}
|
||||
}
|
||||
~MarkerSection() { end(); }
|
||||
|
||||
typename Data::type data = {};
|
||||
|
||||
|
Reference in New Issue
Block a user