Skip to content

Commit

Permalink
fix: #66
Browse files Browse the repository at this point in the history
  • Loading branch information
KusStar committed Mar 30, 2022
1 parent c508ba1 commit 54e74d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(

const commonVariables = useCommonVariables(props);
const { size, handlerOffsetX } = commonVariables;
const dataLength = data.length;

const offsetX = useDerivedValue(() => {
const totalSize = size * data.length;
const totalSize = size * dataLength;
const x = handlerOffsetX.value % totalSize;

if (!loop) {
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useOnProgressChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ export function useOnProgressChange(
} & Pick<TCarouselProps, 'onProgressChange'>
) {
const { offsetX, rawData, size, onProgressChange } = opts;
const rawDataLength = rawData.length;
useAnimatedReaction(
() => offsetX.value,
(_value) => {
let value = _value;

if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {
if (rawDataLength === DATA_LENGTH.SINGLE_ITEM) {
value = value % size;
}

if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {
if (rawDataLength === DATA_LENGTH.DOUBLE_ITEM) {
value = value % (size * 2);
}

let absoluteProgress = Math.abs(value / size);

if (value > 0) {
absoluteProgress = rawData.length - absoluteProgress;
absoluteProgress = rawDataLength - absoluteProgress;
}

!!onProgressChange &&
Expand Down

0 comments on commit 54e74d2

Please sign in to comment.