Skip to content

Commit

Permalink
improve card scrolling performance
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidHaji-zada committed Jan 10, 2024
1 parent fbcad02 commit 3a27cff
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface PaginatedAccountListProps extends AccountListProps {
onScrolIndexChange?: (newPosition: number) => void;
}
const SCROLL_OFFSET_LIMIT = scale(200);
const SCROLL_SPEED_LIMIT = 80;
const SCROLL_SPEED_LIMIT = 40;

export const PaginatedAccountList = (props: PaginatedAccountListProps) => {
const { accounts, listProps, type, onScrolIndexChange } = props;
Expand Down Expand Up @@ -43,7 +43,6 @@ export const PaginatedAccountList = (props: PaginatedAccountListProps) => {
const speed =
(xPos - scrollBegin.current) /
(new Date().getTime() / scrollBeginAt.current);

if (offset < SCROLL_OFFSET_LIMIT && Math.abs(speed) < SCROLL_SPEED_LIMIT) {
// the scroll offset is not enough to change selected card
scrollToItem(currentIdx.current);
Expand Down Expand Up @@ -72,7 +71,9 @@ export const PaginatedAccountList = (props: PaginatedAccountListProps) => {
viewOffset: scale(32)
});
currentIdx.current = idx;
if (typeof onScrolIndexChange === 'function') onScrolIndexChange(idx);
setTimeout(() => {
if (typeof onScrolIndexChange === 'function') onScrolIndexChange(idx);
}, 0);
};

return (
Expand Down

0 comments on commit 3a27cff

Please sign in to comment.