meliorence / meliorence/react-native-snap-carousel

snapToItem doesn't change the current index "quick enough"

Open
#581 5 comments 1 reaction 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

Bug Report

This is a bug report

Have you followed the required steps before opening a bug report?

(Check the step you've followed - put an x character between the square brackets ([]).)

Have you made sure that it wasn't a React Native bug?

Yes

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

Only tested on Ios

Is the bug reproductible in a production environment (not a debug one)?

No

Environment

Environment:

React Native: https://github.com/expo/react-native/archive/sdk-34.0.1.tar.gz
React-native-snap-carousel: ^3.7.5
Target platform: iOS (12.0) -> EXPO

(Write your answer here.)

Expected Behavior

When programmatically snapToItem it will change the current index in the callback of the renderItem function with the correct value.

(Write what you thought would happen.)

See above.

When programmatically changing the snapToItem proving an index doesn't change the currentIndex or doesn't change the currentIndex quick enough in the carousel. So when the render function is being called I am receiving an old current Index which is crashing my existing code.

Reproducible Demo
  renderFiveHundredFilter = ({item, index}) => {
    console.log("CURRENT_INDEX", this._carousel.currentIndex);

     ^^ this._carousel.currentIndex won't change when an item is pressed. It will remain on 0

    return (
      <Text onPress={() => {
        this._carousel.snapToItem(index);
        this.onPrivilegesRangeChange("click", index)
      }
    } key={`abc_${index}`} style={{color: this._carousel.currentIndex === index ? "gold" : "white", fontFamily: Fonts.heavy, fontSize: Fonts.small}}>{item.name}</Text>
    )
  }

Steps to Reproduce
  1. Create a simple Carousel
  2. Change to a snap item programmatically using snapToItem callback function
  3. See if the currentIndex of the carousel is being received in the render function with the correct result.

Contributor guide

Open the contributing guide

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

Reproduce the issue with the provided renderFiveHundredFilter example and a React Native Carousel, focusing on programmatic snapToItem calls and the currentIndex value during rendering. Done means currentIndex reflects the selected item when the render callback runs without crashing dependent code.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.