Skip to content

Commit b5861e2

Browse files
author
Brian Vaughn
committed
Prevent hidden views from triggering cursor/tooltip interactions
1 parent 586aefa commit b5861e2

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

packages/react-devtools-scheduling-profiler/src/view-base/ResizableView.js

+15-19
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ const RESIZE_BAR_DOT_SPACING = 4;
4545
const RESIZE_BAR_HEIGHT = 8;
4646
const RESIZE_BAR_WITH_LABEL_HEIGHT = 16;
4747

48+
const HIDDEN_RECT = {
49+
origin: {x: 0, y: 0},
50+
size: {width: 0, height: 0},
51+
};
52+
4853
class ResizeBar extends View {
4954
_interactionState: ResizeBarState = 'normal';
5055
_label: string;
@@ -238,8 +243,6 @@ export class ResizableView extends View {
238243
this.addSubview(this._subview);
239244
this.addSubview(this._resizeBar);
240245

241-
// TODO (ResizableView) Allow subviews to specify default sizes.
242-
// Maybe that or set some % based default so all panels are visible to begin with.
243246
const subviewDesiredSize = subview.desiredSize();
244247
this._updateLayoutStateAndResizeBar(
245248
subviewDesiredSize.maxInitialHeight != null
@@ -253,14 +256,9 @@ export class ResizableView extends View {
253256

254257
desiredSize() {
255258
const resizeBarDesiredSize = this._resizeBar.desiredSize();
256-
const subviewDesiredSize = this._subview.desiredSize();
257-
258-
const subviewDesiredWidth = subviewDesiredSize
259-
? subviewDesiredSize.width
260-
: 0;
261259

262260
return {
263-
width: Math.max(subviewDesiredWidth, resizeBarDesiredSize.width),
261+
width: this.frame.size.width,
264262
height: this._layoutState.barOffsetY + resizeBarDesiredSize.height,
265263
};
266264
}
@@ -315,19 +313,19 @@ export class ResizableView extends View {
315313

316314
const resizeBarDesiredSize = this._resizeBar.desiredSize();
317315

318-
let currentY = y;
319-
320-
this._subview.setFrame({
321-
origin: {x, y: currentY},
322-
size: {width, height: barOffsetY},
323-
});
324-
currentY += this._subview.frame.size.height;
316+
if (barOffsetY === 0) {
317+
this._subview.setFrame(HIDDEN_RECT);
318+
} else {
319+
this._subview.setFrame({
320+
origin: {x, y},
321+
size: {width, height: barOffsetY},
322+
});
323+
}
325324

326325
this._resizeBar.setFrame({
327-
origin: {x, y: currentY},
326+
origin: {x, y: y + barOffsetY},
328327
size: {width, height: resizeBarDesiredSize.height},
329328
});
330-
currentY += this._resizeBar.frame.size.height;
331329
}
332330

333331
_handleClick(interaction: ClickInteraction) {
@@ -388,8 +386,6 @@ export class ResizableView extends View {
388386
}
389387
}
390388

391-
_didGrab: boolean = false;
392-
393389
getCursorActiveSubView(interaction: Interaction): View | null {
394390
const cursorLocation = interaction.payload.location;
395391
const resizeBarFrame = this._resizeBar.frame;

packages/react-devtools-scheduling-profiler/src/view-base/View.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,18 @@ export class View {
271271
interaction: Interaction,
272272
viewRefs: ViewRefs,
273273
) {
274+
const {subviews, visibleArea} = this;
275+
276+
if (visibleArea.size.height === 0) {
277+
return;
278+
}
279+
274280
this.handleInteraction(interaction, viewRefs);
275-
this.subviews.forEach(subview =>
276-
subview.handleInteractionAndPropagateToSubviews(interaction, viewRefs),
277-
);
281+
282+
subviews.forEach(subview => {
283+
if (rectIntersectsRect(visibleArea, subview.visibleArea)) {
284+
subview.handleInteractionAndPropagateToSubviews(interaction, viewRefs);
285+
}
286+
});
278287
}
279288
}

packages/react-devtools-scheduling-profiler/src/view-base/geometry.js

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ function boxToRect(box: Box): Rect {
7474
}
7575

7676
export function rectIntersectsRect(rect1: Rect, rect2: Rect): boolean {
77+
if (
78+
rect1.width === 0 ||
79+
rect1.height === 0 ||
80+
rect2.width === 0 ||
81+
rect2.height === 0
82+
) {
83+
return false;
84+
}
85+
7786
const [top1, right1, bottom1, left1] = rectToBox(rect1);
7887
const [top2, right2, bottom2, left2] = rectToBox(rect2);
7988
return !(

packages/react-devtools-scheduling-profiler/src/view-base/layouter.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ export const noopLayout: Layouter = layout => layout;
5151
* - `containerWidthLayout`, and
5252
* - `containerHeightLayout`.
5353
*/
54-
export const layeredLayout: Layouter = (layout, containerFrame) =>
55-
layout.map(layoutInfo => ({...layoutInfo, frame: containerFrame}));
54+
export const layeredLayout: Layouter = (layout, containerFrame) => {
55+
return layout.map(layoutInfo => ({...layoutInfo, frame: containerFrame}));
56+
};
5657

5758
/**
5859
* Stacks `views` vertically in `frame`.

0 commit comments

Comments
 (0)