MCPcopy
hub / github.com/facebook/react / displayIfNeeded

Method displayIfNeeded

packages/react-devtools-timeline/src/view-base/View.js:193–223  ·  view source on GitHub ↗

* Executes the display flow if this view needs to be drawn. * * 1. Lays out subviews with `layoutSubviews`. * 2. Draws content with `draw`.

(context: CanvasRenderingContext2D, viewRefs: ViewRefs)

Source from the content-addressed store, hash-verified

191 * 2. Draws content with `draw`.
192 */
193 displayIfNeeded(context: CanvasRenderingContext2D, viewRefs: ViewRefs) {
194 if (
195 (this._needsDisplay || this._subviewsNeedDisplay) &&
196 rectIntersectsRect(this.frame, this.visibleArea) &&
197 !sizeIsEmpty(this.visibleArea.size)
198 ) {
199 this.layoutSubviews();
200 if (this._needsDisplay) {
201 this._needsDisplay = false;
202 }
203 if (this._subviewsNeedDisplay) this._subviewsNeedDisplay = false;
204
205 // Clip anything drawn by the view to prevent it from overflowing its visible area.
206 const visibleArea = this.visibleArea;
207 const region = new Path2D();
208 region.rect(
209 visibleArea.origin.x,
210 visibleArea.origin.y,
211 visibleArea.size.width,
212 visibleArea.size.height,
213 );
214 context.save();
215 context.clip(region);
216 context.beginPath();
217
218 this.draw(context, viewRefs);
219
220 // Stop clipping
221 context.restore();
222 }
223 }
224
225 /**
226 * Layout self and subviews.

Callers 2

CanvasPage.jsFile · 0.45
drawMethod · 0.45

Calls 4

layoutSubviewsMethod · 0.95
drawMethod · 0.95
rectIntersectsRectFunction · 0.90
sizeIsEmptyFunction · 0.90

Tested by

no test coverage detected