Skip to content

Commit dfb4553

Browse files
author
Brian Vaughn
committed
Fixed zoomToRange() helper (which was broken by previous refactor commit)
1 parent d5f817c commit dfb4553

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

packages/react-devtools-scheduling-profiler/src/CanvasPage.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import {
5353
UserTimingMarksView,
5454
} from './content-views';
5555
import {COLORS} from './content-views/constants';
56-
import {clampState} from './view-base/utils/scrollState';
56+
import {clampState, moveStateToRange} from './view-base/utils/scrollState';
5757
import EventTooltip from './EventTooltip';
5858
import {RegistryContext} from 'react-devtools-shared/src/devtools/ContextMenu/Contexts';
5959
import ContextMenu from 'react-devtools-shared/src/devtools/ContextMenu/ContextMenu';
@@ -109,14 +109,24 @@ const zoomToBatch = (
109109
data: ReactProfilerData,
110110
measure: ReactMeasure,
111111
viewState: ViewState,
112+
width: number,
112113
) => {
113114
const {batchUID} = measure;
114-
const [startTime, stopTime] = getBatchRange(batchUID, data);
115-
116-
viewState.updateHorizontalScrollState({
117-
offset: startTime,
118-
length: stopTime - startTime,
115+
const [rangeStart, rangeEnd] = getBatchRange(batchUID, data);
116+
117+
// Convert from time range to ScrollState
118+
const scrollState = moveStateToRange({
119+
state: viewState.horizontalScrollState,
120+
rangeStart,
121+
rangeEnd,
122+
contentLength: data.duration,
123+
124+
minContentLength: data.duration * MIN_ZOOM_LEVEL,
125+
maxContentLength: data.duration * MAX_ZOOM_LEVEL,
126+
containerLength: width,
119127
});
128+
129+
viewState.updateHorizontalScrollState(scrollState);
120130
};
121131

122132
type AutoSizedCanvasProps = {|
@@ -650,7 +660,7 @@ function AutoSizedCanvas({
650660
{measure !== null && (
651661
<ContextMenuItem
652662
onClick={() =>
653-
zoomToBatch(contextData.data, measure, viewState)
663+
zoomToBatch(contextData.data, measure, viewState, width)
654664
}
655665
title="Zoom to batch">
656666
Zoom to batch

packages/react-devtools-scheduling-profiler/src/SchedulingProfilerContext.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ function SchedulingProfilerContextController({children}: Props) {
6969
horizontalScrollState.offset = scrollState.offset;
7070
horizontalScrollState.length = scrollState.length;
7171

72-
horizontalScrollStateChangeCallbacks.forEach(callback =>
73-
callback(scrollState),
74-
);
72+
horizontalScrollStateChangeCallbacks.forEach(callback => {
73+
callback(scrollState);
74+
});
7575
},
7676
viewToMutableViewStateMap: new Map(),
7777
};

0 commit comments

Comments
 (0)