Skip to content

Commit

Permalink
refactor: improving readability of computeTranslation function
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienIzz committed Feb 9, 2024
1 parent a02f671 commit 91d4e6a
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,22 @@ const computeStickToEndTranslation = <T>({
listSizeInPx: number;
maxPossibleRightAlignedIndex: number;
}) => {
const scrollOffset =
currentlyFocusedItemIndex > maxPossibleRightAlignedIndex
? getSizeInPxFromOneItemToAnother(data, itemSizeInPx, 0, currentlyFocusedItemIndex) +
(typeof itemSizeInPx === 'function'
? itemSizeInPx(data[currentlyFocusedItemIndex])
: itemSizeInPx) -
listSizeInPx
: 0;
if (currentlyFocusedItemIndex <= maxPossibleRightAlignedIndex) return -0;

const currentlyFocusedItemSize =
typeof itemSizeInPx === 'function'
? itemSizeInPx(data[currentlyFocusedItemIndex])
: itemSizeInPx;

const sizeOfListFromStartToCurrentlyFocusedItem = getSizeInPxFromOneItemToAnother(
data,
itemSizeInPx,
0,
currentlyFocusedItemIndex,
);

const scrollOffset =
sizeOfListFromStartToCurrentlyFocusedItem + currentlyFocusedItemSize - listSizeInPx;
return -scrollOffset;
};

Expand Down

0 comments on commit 91d4e6a

Please sign in to comment.