Skip to content

Commit

Permalink
feat: export cancelScroll handle
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jan 5, 2025
1 parent 7539c2a commit 32bfc46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export type Scroller = {
$scrollBy: (offset: number) => void;
$scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;
$fixScrollJump: () => void;
$cancelScroll: () => void;
};

/**
Expand Down Expand Up @@ -369,6 +370,9 @@ export const createScroller = (
$fixScrollJump: () => {
scrollObserver && scrollObserver._fixScrollJump();
},
$cancelScroll: () => {
cancelScroll && cancelScroll();
},
};
};

Expand Down Expand Up @@ -581,11 +585,11 @@ export const createWindowScroller = (
store.$getItemOffset(index) +
(align === "end"
? store.$getItemSize(index) -
(store.$getViewportSize() - getScrollbarSize())
(store.$getViewportSize() - getScrollbarSize())
: align === "center"
? (store.$getItemSize(index) -
(store.$getViewportSize() - getScrollbarSize())) /
2
(store.$getViewportSize() - getScrollbarSize())) /
2
: 0)
);
}, smooth);
Expand Down
5 changes: 5 additions & 0 deletions src/react/Virtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export interface VirtualizerHandle {
* @param offset offset from current position
*/
scrollBy(offset: number): void;
/**
* Cancel unfinished scroll.
*/
cancelScroll(): void;
}

/**
Expand Down Expand Up @@ -321,6 +325,7 @@ export const Virtualizer = forwardRef<VirtualizerHandle, VirtualizerProps>(
scrollToIndex: scroller.$scrollToIndex,
scrollTo: scroller.$scrollTo,
scrollBy: scroller.$scrollBy,
cancelScroll: scroller.$cancelScroll,
};
}, []);

Expand Down

0 comments on commit 32bfc46

Please sign in to comment.