Skip to content

Commit

Permalink
feat: added onSnapToItem trigger for didMount and update index changi…
Browse files Browse the repository at this point in the history
…ng logic
  • Loading branch information
karkengc committed Jan 8, 2024
1 parent 4602ff0 commit 35a5930
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
[getCurrentIndex, next, prev, scrollTo],
);

React.useEffect(() => {
// add onSnapToItem call when component is first mounted
onSnapToItem?.(defaultIndex || 0);
}, []);

const visibleRanges = useVisibleRanges({
total: dataLength,
viewSize: size,
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useOnProgressChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export function useOnProgressChange(
if (value > 0)
absoluteProgress = rawDataLength - absoluteProgress;

if (absoluteProgress > (rawDataLength - 0.5)) // threshold set as half of the size
absoluteProgress = 0;

if (onProgressChange)
runOnJS(onProgressChange)(value, absoluteProgress);
},
Expand Down

0 comments on commit 35a5930

Please sign in to comment.