Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduling Profiler: Add network measures #22112

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,34 @@ export function trimText(
text: string,
width: number,
): string | null {
for (let i = text.length - 1; i >= 0; i--) {
const trimmedText = i === text.length - 1 ? text : text.substr(0, i) + '…';
const maxIndex = text.length - 1;

let startIndex = 0;
let stopIndex = maxIndex;

let longestValidIndex = 0;
let longestValidText = null;

// Trimming long text could be really slow if we decrease only 1 character at a time.
// Trimming with more of a binary search approach is faster in the worst cases.
while (startIndex <= stopIndex) {
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
const currentIndex = Math.floor((startIndex + stopIndex) / 2);
const trimmedText =
currentIndex === maxIndex ? text : text.substr(0, currentIndex) + '…';

if (getTextWidth(context, trimmedText) <= width) {
return trimmedText;
if (longestValidIndex < currentIndex) {
longestValidIndex = currentIndex;
longestValidText = trimmedText;
}

startIndex = currentIndex + 1;
} else {
stopIndex = currentIndex - 1;
}
}

return null;
return longestValidText;
}

type TextConfig = {|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class HorizontalPanAndZoomView extends View {
interaction.payload.location,
this.frame,
);
if (isHovered) {
if (isHovered && viewRefs.hoveredView === null) {
viewRefs.hoveredView = this;
}

Expand All @@ -169,9 +169,16 @@ export class HorizontalPanAndZoomView extends View {
if (!this._isPanning) {
return;
}

// Don't prevent mouse-move events from bubbling if they are vertical drags.
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
const {movementX, movementY} = interaction.payload.event;
if (Math.abs(movementX) < Math.abs(movementY)) {
return;
}

const newState = translateState({
state: this._viewState.horizontalScrollState,
delta: interaction.payload.event.movementX,
delta: movementX,
containerLength: this.frame.size.width,
});
this._viewState.updateHorizontalScrollState(newState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,20 @@ export class VerticalScrollView extends View {
if (!this._isPanning) {
return;
}

// Don't prevent mouse-move events from bubbling if they are horizontal drags.
const {movementX, movementY} = interaction.payload.event;
if (Math.abs(movementX) > Math.abs(movementY)) {
return;
}

const newState = translateState({
state: this._scrollState,
delta: interaction.payload.event.movementY,
containerLength: this.frame.size.height,
});
this._setScrollState(newState);

return true;
}

Expand Down Expand Up @@ -255,12 +263,14 @@ export class VerticalScrollView extends View {
}

_setScrollState(proposedState: ScrollState): boolean {
const height = this._contentView.frame.size.height;
const contentHeight = this._contentView.frame.size.height;
const containerHeight = this.frame.size.height;

const clampedState = clampState({
state: proposedState,
minContentLength: height,
maxContentLength: height,
containerLength: this.frame.size.height,
minContentLength: contentHeight,
maxContentLength: contentHeight,
containerLength: containerHeight,
});
if (!areScrollStatesEqual(clampedState, this._scrollState)) {
this._scrollState.offset = clampedState.offset;
Expand All @@ -275,6 +285,13 @@ export class VerticalScrollView extends View {
return true;
}

return false;
// Don't allow wheel events to bubble past this view even if we've scrolled to the edge.
// It just feels bad to have the scrolling jump unexpectedly from in a container to the outer page.
// The only exception is when the container fitst the contnet (no scrolling).
if (contentHeight === containerHeight) {
return false;
}

return true;
}
}