import type { ICarouselInstance } from 'react-native-reanimated-carousel'; type CarouselPaginationScrollAction = NonNullable[0]>; /** * Resolves the shortest `scrollTo` action for pagination dot presses. * * In loop mode the library's absolute `scrollTo({ index })` can animate through every * slide when the current index is past the halfway point of the loop buffer (e.g. index 2 → 3 * with four items). Relative `count` navigation avoids that wrap-around path. */ export function resolveCarouselPaginationScrollAction( currentIndex: number, targetIndex: number, dataLength: number, loop: boolean, ): CarouselPaginationScrollAction | null { if (currentIndex === targetIndex) return null; if (!loop) { return { index: targetIndex, animated: true }; } const forwardDelta = (targetIndex - currentIndex + dataLength) % dataLength; const backwardDelta = (currentIndex - targetIndex + dataLength) % dataLength; if (forwardDelta <= backwardDelta) { return { count: forwardDelta, animated: true }; } return { count: -backwardDelta, animated: true }; }