Skip to content

Commit 407b310

Browse files
author
Brian Vaughn
committed
Scroll view shows up/down caret overlay indicating content is above or below the fold
1 parent 3002ebf commit 407b310

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

packages/react-devtools-scheduling-profiler/src/content-views/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export let COLORS = {
7373
REACT_SUSPENSE_UNRESOLVED_EVENT: '',
7474
REACT_SUSPENSE_UNRESOLVED_EVENT_HOVER: '',
7575
REACT_WORK_BORDER: '',
76+
SCROLL_CARET: '',
7677
TEXT_COLOR: '',
7778
TIME_MARKER_LABEL: '',
7879
WARNING_BACKGROUND: '',
@@ -172,6 +173,7 @@ export function updateColorsToMatchTheme(): void {
172173
REACT_WORK_BORDER: computedStyle.getPropertyValue(
173174
'--color-scheduling-profiler-react-work-border',
174175
),
176+
SCROLL_CARET: computedStyle.getPropertyValue('--color-scroll-caret'),
175177
TEXT_COLOR: computedStyle.getPropertyValue(
176178
'--color-scheduling-profiler-text-color',
177179
),

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

+49
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
} from './useCanvasInteraction';
1717
import type {Rect} from './geometry';
1818
import type {ScrollState} from './utils/scrollState';
19+
import type {ViewRefs} from './Surface';
1920

2021
import {Surface} from './Surface';
2122
import {View} from './View';
@@ -26,6 +27,11 @@ import {
2627
translateState,
2728
} from './utils/scrollState';
2829
import {MOVE_WHEEL_DELTA_THRESHOLD} from './constants';
30+
import {COLORS} from '../content-views/constants';
31+
32+
const CARET_MARGIN = 3;
33+
const CARET_WIDTH = 5;
34+
const CARET_HEIGHT = 3;
2935

3036
// TODO VerticalScrollView Draw caret over top+center and/or bottom+center to indicate scrollable content.
3137
export class VerticalScrollView extends View {
@@ -49,6 +55,49 @@ export class VerticalScrollView extends View {
4955
return this._contentView.desiredSize();
5056
}
5157

58+
draw(context: CanvasRenderingContext2D, viewRefs: ViewRefs) {
59+
super.draw(context, viewRefs);
60+
61+
const offset = this._scrollState.offset;
62+
const desiredSize = this._contentView.desiredSize();
63+
64+
const above = offset;
65+
const below = this.frame.size.height - desiredSize.height - offset;
66+
67+
if (above < 0 || below < 0) {
68+
const {visibleArea} = this;
69+
const {x, y} = visibleArea.origin;
70+
const {width, height} = visibleArea.size;
71+
const horizontalCenter = x + width / 2;
72+
73+
const halfWidth = CARET_WIDTH;
74+
75+
if (above < 0) {
76+
const topY = y + CARET_MARGIN;
77+
78+
context.beginPath();
79+
context.moveTo(horizontalCenter, topY);
80+
context.lineTo(horizontalCenter + halfWidth, topY + CARET_HEIGHT);
81+
context.lineTo(horizontalCenter - halfWidth, topY + CARET_HEIGHT);
82+
context.closePath();
83+
context.fillStyle = COLORS.SCROLL_CARET;
84+
context.fill();
85+
}
86+
87+
if (below < 0) {
88+
const bottomY = y + height - CARET_MARGIN;
89+
90+
context.beginPath();
91+
context.moveTo(horizontalCenter, bottomY);
92+
context.lineTo(horizontalCenter + halfWidth, bottomY - CARET_HEIGHT);
93+
context.lineTo(horizontalCenter - halfWidth, bottomY - CARET_HEIGHT);
94+
context.closePath();
95+
context.fillStyle = COLORS.SCROLL_CARET;
96+
context.fill();
97+
}
98+
}
99+
}
100+
52101
/**
53102
* Reference to the content view. This view is also the only view in
54103
* `this.subviews`.

packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js

+1
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ export function updateThemeVariables(
559559
'color-scheduling-profiler-react-work-border',
560560
documentElements,
561561
);
562+
updateStyleHelper(theme, 'color-scroll-caret', documentElements);
562563
updateStyleHelper(theme, 'color-shadow', documentElements);
563564
updateStyleHelper(theme, 'color-tab-selected-border', documentElements);
564565
updateStyleHelper(theme, 'color-text', documentElements);

packages/react-devtools-shared/src/devtools/views/root.css

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
--light-color-search-match-current: #f7923b;
114114
--light-color-selected-tree-highlight-active: rgba(0, 136, 250, 0.1);
115115
--light-color-selected-tree-highlight-inactive: rgba(0, 0, 0, 0.05);
116+
--light-color-scroll-caret: #d1d1d1;
116117
--light-color-shadow: rgba(0, 0, 0, 0.25);
117118
--light-color-tab-selected-border: #0088fa;
118119
--light-color-text: #000000;
@@ -239,6 +240,7 @@
239240
--dark-color-search-match-current: #f7923b;
240241
--dark-color-selected-tree-highlight-active: rgba(23, 143, 185, 0.15);
241242
--dark-color-selected-tree-highlight-inactive: rgba(255, 255, 255, 0.05);
243+
--dark-color-scroll-caret: #4f5766;
242244
--dark-color-shadow: rgba(0, 0, 0, 0.5);
243245
--dark-color-tab-selected-border: #178fb9;
244246
--dark-color-text: #ffffff;

0 commit comments

Comments
 (0)