Skip to content

Commit f86aae0

Browse files
authored
Simplify stick scroll in overview (#8336)
* undo sticky scroll revert * Simplify stick scroll in overview
1 parent 9d49256 commit f86aae0

File tree

2 files changed

+2
-118
lines changed

2 files changed

+2
-118
lines changed

webviews/editorWebview/index.css

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ textarea:focus,
4848
}
4949

5050
.title {
51-
/* position: sticky; */
51+
position: sticky;
5252
top: 0;
5353
z-index: 100;
5454
display: flex;
@@ -63,33 +63,6 @@ textarea:focus,
6363
flex: 1;
6464
}
6565

66-
/* Shadow effect when stuck - only on bottom */
67-
.title.stuck::after {
68-
content: '';
69-
position: absolute;
70-
bottom: 0;
71-
left: 0;
72-
right: 0;
73-
height: 1px;
74-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
75-
pointer-events: none;
76-
}
77-
78-
/* Hide subtitle when stuck */
79-
.title.stuck .subtitle {
80-
display: none;
81-
}
82-
83-
/* Hide edit button when stuck */
84-
.title.stuck #edit-title-button {
85-
display: none;
86-
}
87-
88-
/* Adjust title size when stuck */
89-
.title.stuck .overview-title h2 {
90-
font-size: 18px;
91-
}
92-
9366
.title .pr-number {
9467
margin-left: 5px;
9568
}

webviews/editorWebview/overview.tsx

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -31,98 +31,9 @@ const useMediaQuery = (query: string) => {
3131

3232
export const Overview = (pr: PullRequest) => {
3333
const isSingleColumnLayout = useMediaQuery('(max-width: 768px)');
34-
const titleRef = React.useRef<HTMLDivElement>(null);
35-
const stickyHeightRef = React.useRef(0);
36-
const collapseDeltaRef = React.useRef(0);
37-
38-
React.useEffect(() => {
39-
const title = titleRef.current;
40-
41-
if (!title) {
42-
return;
43-
}
44-
45-
// Small threshold to account for sub-pixel rendering
46-
const STICKY_THRESHOLD = 1;
47-
48-
const measureStickyMetrics = () => {
49-
const wasStuck = title.classList.contains('stuck');
50-
if (!wasStuck) {
51-
title.classList.remove('stuck');
52-
}
53-
54-
const unstuckHeight = title.getBoundingClientRect().height;
55-
// title.classList.add('stuck');
56-
const stuckHeight = title.getBoundingClientRect().height;
57-
stickyHeightRef.current = stuckHeight;
58-
collapseDeltaRef.current = Math.max(0, unstuckHeight - stuckHeight);
59-
60-
if (!wasStuck) {
61-
title.classList.remove('stuck');
62-
}
63-
};
64-
65-
const hasEnoughScroll = () => {
66-
const doc = document.documentElement;
67-
const body = document.body;
68-
const scrollHeight = Math.max(doc.scrollHeight, body.scrollHeight);
69-
const availableScroll = scrollHeight - window.innerHeight;
70-
const adjustment = title.classList.contains('stuck') ? collapseDeltaRef.current : 0;
71-
return availableScroll + adjustment >= stickyHeightRef.current;
72-
};
73-
74-
// Use scroll event with requestAnimationFrame to detect when title becomes sticky
75-
// Check if the title's top position is at the viewport top (sticky position)
76-
let ticking = false;
77-
const handleScroll = () => {
78-
if (ticking) {
79-
return;
80-
}
81-
82-
ticking = true;
83-
window.requestAnimationFrame(() => {
84-
if (!hasEnoughScroll()) {
85-
title.classList.remove('stuck');
86-
ticking = false;
87-
return;
88-
}
89-
90-
const rect = title.getBoundingClientRect();
91-
// Title is stuck when its top is at position 0 (sticky top: 0)
92-
if (rect.top <= STICKY_THRESHOLD) {
93-
// title.classList.add('stuck');
94-
} else {
95-
title.classList.remove('stuck');
96-
}
97-
ticking = false;
98-
});
99-
};
100-
101-
const handleResize = () => {
102-
measureStickyMetrics();
103-
handleScroll();
104-
};
105-
106-
measureStickyMetrics();
107-
108-
// Check initial state after a brief delay to ensure layout is settled
109-
const timeoutId = setTimeout(() => {
110-
measureStickyMetrics();
111-
handleScroll();
112-
}, 100);
113-
114-
window.addEventListener('scroll', handleScroll, { passive: true });
115-
window.addEventListener('resize', handleResize);
116-
117-
return () => {
118-
clearTimeout(timeoutId);
119-
window.removeEventListener('scroll', handleScroll);
120-
window.removeEventListener('resize', handleResize);
121-
};
122-
}, []);
12334

12435
return <>
125-
<div id="title" className="title" ref={titleRef}>
36+
<div id="title" className="title">
12637
<div className="details">
12738
<Header {...pr} />
12839
</div>

0 commit comments

Comments
 (0)