leecade / leecade/react-native-swiper

scrollTo / scrollBy on mount fails (NaN)

Open
#1,192 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.5k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

Which OS ?

Android

Version

Which versions are you using:

  • react-native-swiper v1.6.0
  • react-native v61.x
Expected behaviour

When you call carouselRef.current.scrollTo(slides.length - 1, true);
it should transition to the last slide

Actual behaviour

It doesn't do anything bc his.internals.offset[dir] is undefined, leading
https://github.com/leecade/react-native-swiper/blob/master/src/index.js#L467 to result in NaN

Solution possibly:
const diff = offset[dir] - (this.internals.offset[dir] || 0)

How to reproduce it>

call scrollTo or scrollBy after mount before you swiped

Steps to reproduce
  1. mount component
  2. call carouselRef.current.scrollTo(slides.length - 1, true);

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/index.js around line 467 and trace how scrollTo and scrollBy calculate the offset immediately after mount. Reproduce the issue on Android with react-native-swiper v1.6.0 and React Native v61.x by calling scrollTo or scrollBy before swiping; done means the carousel transitions without producing NaN.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.