Skip to content

Commit d930f40

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 d930f40

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 54 additions & 0 deletions
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,54 @@ 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+
// Show carets if there's scroll overflow above or below the viewable area.
62+
if (this.frame.size.height > CARET_HEIGHT * 2 + CARET_MARGIN * 3) {
63+
const offset = this._scrollState.offset;
64+
const desiredSize = this._contentView.desiredSize();
65+
66+
const above = offset;
67+
const below = this.frame.size.height - desiredSize.height - offset;
68+
69+
if (above < 0 || below < 0) {
70+
const {visibleArea} = this;
71+
const {x, y} = visibleArea.origin;
72+
const {width, height} = visibleArea.size;
73+
const horizontalCenter = x + width / 2;
74+
75+
const halfWidth = CARET_WIDTH;
76+
const left = horizontalCenter + halfWidth;
77+
const right = horizontalCenter - halfWidth;
78+
79+
if (above < 0) {
80+
const topY = y + CARET_MARGIN;
81+
82+
context.beginPath();
83+
context.moveTo(horizontalCenter, topY);
84+
context.lineTo(left, topY + CARET_HEIGHT);
85+
context.lineTo(right, topY + CARET_HEIGHT);
86+
context.closePath();
87+
context.fillStyle = COLORS.SCROLL_CARET;
88+
context.fill();
89+
}
90+
91+
if (below < 0) {
92+
const bottomY = y + height - CARET_MARGIN;
93+
94+
context.beginPath();
95+
context.moveTo(horizontalCenter, bottomY);
96+
context.lineTo(left, bottomY - CARET_HEIGHT);
97+
context.lineTo(right, bottomY - CARET_HEIGHT);
98+
context.closePath();
99+
context.fillStyle = COLORS.SCROLL_CARET;
100+
context.fill();
101+
}
102+
}
103+
}
104+
}
105+
52106
/**
53107
* Reference to the content view. This view is also the only view in
54108
* `this.subviews`.

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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)