leecade / leecade/react-native-swiper
index prop does not work when loop={true}
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.5k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
As noted in #82 the index prop can be used to maintain the index on state change. (Otherwise, a re-render resets the swiper to the initial position.) However, I noticed that this solution only works for me when loop={false}. The problem when loop={true} is the position of the swiper resets to the first child element.
Upon closer inspection, the index on the internal context is what it should be. The problems looks to be in the initState method the setup variable is always set to 1 when props.loop is true ( var setup = props.loop ? 1 : initState.index;).
I believe changing that line to the following will fix the issue.
var setup = initState.index
if ( props.loop ) {
setup++
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the initState method and the setup calculation shown in the issue, then trace how the internal context index is used when loop is true. Verify the behavior by checking that a rerender preserves the swiper's current position instead of resetting to the first child element.
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
- 52/100