Skip to content

Commit fe6c8c5

Browse files
zombieJclaude
andcommitted
refactor: replace custom scroll with native CSS scrolling
- Remove useListScroll hook entirely - Use native browser scrolling via overflow-y: auto - Hide scrollbars with CSS for cleaner appearance - Return totalHeight from useListPosition for content sizing - Simplify NotificationList by removing manual scroll handling Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0874312 commit fe6c8c5

File tree

5 files changed

+45
-163
lines changed

5 files changed

+45
-163
lines changed

assets/geek.less

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717
overflow: hidden;
1818
overscroll-behavior: contain;
1919

20+
&-list {
21+
overflow-x: hidden;
22+
overflow-y: auto;
23+
overscroll-behavior: contain;
24+
-ms-overflow-style: none;
25+
scrollbar-width: none;
26+
27+
&::-webkit-scrollbar {
28+
display: none;
29+
width: 0;
30+
height: 0;
31+
}
32+
}
33+
2034
&-list-content {
2135
position: relative;
2236
display: flex;

assets/index.less

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
pointer-events: none;
1717
flex-direction: column;
1818

19+
&-list {
20+
overflow-x: hidden;
21+
overflow-y: auto;
22+
-ms-overflow-style: none;
23+
scrollbar-width: none;
24+
25+
&::-webkit-scrollbar {
26+
display: none;
27+
width: 0;
28+
height: 0;
29+
}
30+
}
31+
1932
// Position
2033
&-top,
2134
&-topLeft,
@@ -126,6 +139,10 @@
126139
}
127140
}
128141

142+
&-list-content {
143+
position: relative;
144+
}
145+
129146
&-fade {
130147
overflow: hidden;
131148
transition: all 0.3s;

src/NotificationList.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Notification, {
1111
type NotificationStyles,
1212
} from './Notification';
1313
import useListPosition from './hooks/useListPosition';
14-
import useListScroll from './hooks/useListScroll';
1514
import useStack from './hooks/useStack';
1615
import { composeRef } from '@rc-component/util/lib/ref';
1716

@@ -89,9 +88,12 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
8988
}, [expanded, offset, stackEnabled, threshold]);
9089

9190
const [gap, setGap] = React.useState(0);
92-
const [notificationPosition, setNodeSize] = useListPosition(configList, stackPosition, gap);
93-
const { contentRef, onTouchEnd, onTouchMove, onTouchStart, onWheel, scrollOffset, viewportRef } =
94-
useListScroll(keyList, notificationPosition, expanded);
91+
const contentRef = React.useRef<HTMLDivElement>(null);
92+
const [notificationPosition, setNodeSize, totalHeight] = useListPosition(
93+
configList,
94+
stackPosition,
95+
gap,
96+
);
9597

9698
React.useEffect(() => {
9799
const listNode = contentRef.current;
@@ -122,23 +124,18 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
122124
[`${prefixCls}-stack-expanded`]: expanded,
123125
},
124126
)}
125-
onTouchEnd={onTouchEnd}
126-
onTouchMove={onTouchMove}
127-
onTouchStart={onTouchStart}
128-
onWheel={onWheel}
129127
onMouseEnter={() => {
130128
setListHovering(true);
131129
}}
132130
onMouseLeave={() => {
133131
setListHovering(false);
134132
}}
135-
ref={viewportRef}
136133
style={style}
137134
>
138135
<div
139136
className={`${listPrefixCls}-content`}
140137
style={{
141-
transform: `translate3d(0, ${scrollOffset}px, 0)`,
138+
height: totalHeight,
142139
}}
143140
ref={contentRef}
144141
>

src/hooks/useListPosition/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export default function useListPosition(
1414
) {
1515
const [sizeMap, setNodeSize] = useSizes();
1616

17-
const notificationPosition = React.useMemo(() => {
17+
const [notificationPosition, totalHeight] = React.useMemo(() => {
1818
let offsetY = 0;
1919
let offsetBottom = 0;
20+
let nextTotalHeight = 0;
2021
const nextNotificationPosition = new Map<string, NodePosition>();
2122

2223
configList
@@ -31,15 +32,18 @@ export default function useListPosition(
3132
};
3233

3334
nextNotificationPosition.set(key, nodePosition);
35+
36+
nextTotalHeight = Math.max(nextTotalHeight, nodePosition.y + height);
37+
3438
if (stack) {
3539
offsetBottom = nodePosition.y + height;
3640
} else {
3741
offsetY += height + gap;
3842
}
3943
});
4044

41-
return nextNotificationPosition;
45+
return [nextNotificationPosition, nextTotalHeight] as const;
4246
}, [configList, gap, sizeMap, stack]);
4347

44-
return [notificationPosition, setNodeSize] as const;
48+
return [notificationPosition, setNodeSize, totalHeight] as const;
4549
}

src/hooks/useListScroll.ts

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)