Skip to content

fix: non-loop scrollTo offset regression#891

Merged
dohooo merged 5 commits intodohooo:mainfrom
notsuhas:codex/fix-nonloop-scrollto-offset-main
Mar 2, 2026
Merged

fix: non-loop scrollTo offset regression#891
dohooo merged 5 commits intodohooo:mainfrom
notsuhas:codex/fix-nonloop-scrollto-offset-main

Conversation

@notsuhas
Copy link
Contributor

Summary

This fixes a non-loop scrollTo({ index }) regression where navigating backward could produce a positive offset and briefly render a blank item/state.

User Impact

In v5.0.0-beta.4, when loop={false} and a consumer computes a previous index manually (for example with modulo arithmetic) then calls scrollTo({ index: prevIndex, animated: false }), some transitions can land in an invalid offset direction. That can surface as a blank frame/item.

v5.0.0-beta.0 did not show this behavior in the same usage pattern.

Root Cause

useCarouselController used loop-style direction math inside to() for both loop and non-loop modes. In non-loop mode, moving to a lower target index could flip direction and compute a positive final offset.

Fix

In non-loop mode, scrollTo({ index }) now uses direct page mapping:

  • finalOffset = -index * size

Loop mode keeps existing direction and wrap behavior.

Tests

Added regression coverage in useCarouselController.test.tsx:

  • should keep negative offsets when scrollTo() moves backward in non-loop mode
  • should map scrollTo({ index: 0 }) to zero offset from end in non-loop mode

Also re-ran the existing non-loop left-overscroll integration check in Carousel.test.tsx (targeted test).

Validation Run

  • yarn test src/hooks/useCarouselController.test.tsx --runInBand --watchman=false
  • yarn test src/components/Carousel.test.tsx -t "left overscroll" --runInBand --watchman=false

@changeset-bot
Copy link

changeset-bot bot commented Feb 25, 2026

🦋 Changeset detected

Latest commit: e20fd99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-native-reanimated-carousel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Feb 25, 2026

@notsuhas is attempting to deploy a commit to the Caspian's Team Team on Vercel.

A member of the Team first needs to authorize it.

@notsuhas notsuhas changed the title [codex] fix non-loop scrollTo offset regression fix: non-loop scrollTo offset regression Feb 25, 2026
@notsuhas notsuhas marked this pull request as ready for review February 25, 2026 07:25
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Feb 25, 2026
@dosubot
Copy link

dosubot bot commented Feb 25, 2026

Related Documentation

Checked 4 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 2, 2026
@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.32%. Comparing base (5289d9d) to head (e20fd99).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #891      +/-   ##
==========================================
+ Coverage   84.06%   84.32%   +0.25%     
==========================================
  Files          37       37              
  Lines        1042     1040       -2     
  Branches      364      362       -2     
==========================================
+ Hits          876      877       +1     
  Misses         67       67              
+ Partials       99       96       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dohooo dohooo merged commit 73d066d into dohooo:main Mar 2, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants