Skip to content

Commit 5fc2c91

Browse files
committed
fix: not scroll
1 parent 805dae2 commit 5fc2c91

File tree

3 files changed

+5
-34
lines changed

3 files changed

+5
-34
lines changed

examples/nest.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const MyItem: React.ForwardRefRenderFunction<any, Item> = ({ id }, ref) => (
2525
boxSizing: 'border-box',
2626
background: 'white',
2727
}}
28-
debug={`inner_${id}`}
28+
// debug={`inner_${id}`}
2929
>
3030
{(item, index, props) => (
3131
<div {...(item as any)} {...props} style={{ height: 20, border: '1px solid cyan' }}>
@@ -56,7 +56,7 @@ const Demo = () => {
5656
boxSizing: 'border-box',
5757
}}
5858
onScroll={onScroll}
59-
debug="outer"
59+
// debug="outer"
6060
>
6161
{(item, _, props) => <ForwardMyItem {...item} {...props} />}
6262
</List>

src/List.tsx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ export interface ListProps<T> extends Omit<React.HTMLAttributes<any>, 'children'
8888

8989
/** Render extra content into Filler */
9090
extraRender?: (info: ExtraRenderInfo) => React.ReactNode;
91-
92-
/** Not working in prod */
93-
debug?: string;
9491
}
9592

9693
export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
@@ -114,7 +111,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
114111
innerProps,
115112
extraRender,
116113
styles,
117-
debug,
118114
...restProps
119115
} = props;
120116

@@ -383,8 +379,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
383379

384380
const onWheelDelta: Parameters<typeof useFrameWheel>[6] = useEvent((offsetXY, fromHorizontal) => {
385381
if (fromHorizontal) {
386-
// Horizontal scroll no need sync virtual position
387-
388382
flushSync(() => {
389383
setOffsetLeft((left) => {
390384
const nextOffsetLeft = left + (isRTL ? -offsetXY : offsetXY);
@@ -395,20 +389,12 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
395389

396390
triggerScroll();
397391
} else {
398-
// let isScrollOutOfBoundary = false;
399392
syncScrollTop((top) => {
400393
const newTop = top + offsetXY;
401394

402-
// const alignedTop = keepInRange(newTop);
403-
// isScrollOutOfBoundary = alignedTop !== newTop;
404-
405395
return newTop;
406396
});
407-
408-
// return !isScrollOutOfBoundary;
409397
}
410-
411-
// return true;
412398
});
413399

414400
// Since this added in global,should use ref to keep update
@@ -420,20 +406,8 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
420406
isScrollAtRight,
421407
!!scrollWidth,
422408
onWheelDelta,
423-
debug,
424409
);
425410

426-
// const onDeduplicatedRawWheel: typeof onRawWheel = useEvent((e) => {
427-
// const event = e as WheelEvent & {
428-
// _virtualHandled?: boolean;
429-
// };
430-
431-
// // Fix nest List trigger Wheel event
432-
// if (!event._virtualHandled) {
433-
// event._virtualHandled = true;
434-
// onRawWheel(event);
435-
// }
436-
// });
437411
const onDeduplicatedRawWheel = onRawWheel;
438412

439413
// Mobile touch move

src/hooks/useFrameWheel.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default function useFrameWheel(
1919
* Return `true` when you need to prevent default event
2020
*/
2121
onWheelDelta: (offset: number, horizontal: boolean) => void,
22-
debugName?: string,
2322
): [(e: WheelEvent) => void, (e: FireFoxDOMMouseScrollEvent) => void] {
2423
const offsetRef = useRef(0);
2524
const nextFrameRef = useRef<number>(null);
@@ -39,15 +38,10 @@ export default function useFrameWheel(
3938
function onWheelY(e: WheelEvent, deltaY: number) {
4039
raf.cancel(nextFrameRef.current);
4140

42-
offsetRef.current += deltaY;
43-
wheelValueRef.current = deltaY;
44-
4541
// Do nothing when scroll at the edge, Skip check when is in scroll
4642
if (originScroll(false, deltaY)) {
47-
console.log(debugName, 'native scroll');
4843
return;
4944
}
50-
console.log(debugName, 'virtual scroll', deltaY);
5145

5246
// Skip if nest List has handled this event
5347
const event = e as WheelEvent & {
@@ -59,6 +53,9 @@ export default function useFrameWheel(
5953
return;
6054
}
6155

56+
offsetRef.current += deltaY;
57+
wheelValueRef.current = deltaY;
58+
6259
// Proxy of scroll events
6360
if (!isFF) {
6461
event.preventDefault();

0 commit comments

Comments
 (0)