Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index incorrect when data length changed. #281

Closed
nightness opened this issue Oct 14, 2022 · 11 comments
Closed

Index incorrect when data length changed. #281

nightness opened this issue Oct 14, 2022 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@nightness
Copy link

nightness commented Oct 14, 2022

Demo to reproduce:
https://github.com/nightness/carousel-bug

Existing Behaviour:
When swiping left to right on the 0th (initial) item, loads more but changes currentIndex to the end of the list after data updates.

Desired Behaviour:
When I add to the length of data, the current Index doesn't change. I don't want to see that jump to the end of the list of data.

@nightness nightness added the bug Something isn't working label Oct 14, 2022
@dohooo
Copy link
Owner

dohooo commented Oct 15, 2022

Re #191, #181

Some known problems are logical issues, such as this
#181 (comment)

@dohooo
Copy link
Owner

dohooo commented Oct 15, 2022

Do you have any good ideas about controlling the index when dynamic modifying the data length? I think setting it manually is the safe way because I don't know what the user wants the index to do.
And if the data set changed, I don't know which item is the prevent item. 😵‍💫

@nightness
Copy link
Author

nightness commented Oct 17, 2022

I had a chance to take a good look at the code today, and yes, I've some ideas. Give me a day or two to work on it. I also plan to implement onEndReachedThreshold and onEndReached (like FlatList uses) to keep the scrolling smooth.

@RGDEV2022
Copy link

RGDEV2022 commented Oct 19, 2022

@dohooo is there anyway to get an onIndexChanged or similar prop so that we can set the pagination dot to the next index without needing the item to snap first?

If I want to set a scrollAnimationDuration of 1000 for example, and use onSnapToItem to set the index of the dot, it takes 1sec to update.

Is there a workaround we could use for now?

Edit: Same issue using onProgressChanged as well. There is a lag in the index change

@dohooo
Copy link
Owner

dohooo commented Oct 19, 2022

Can it help you for pagination? @RGDEV2022

@RGDEV2022
Copy link

@dohooo I'm confused. Even using that example the index is only changed when the item has actually snapped and it's not immediate on swipe. Here's my code

<Carousel
        ref={carouselRef}
        pagingEnabled
        loop={false}
        mode='vertical-stack'
        snapEnabled
        modeConfig={{
          snapDirection: 'left',
          stackInterval: 15,
          rotateZDeg: 0,
          showLength: 2
        }}
        data={data}
        width={width}
        height={100}
        renderItem={renderItem}
        onProgressChange={(_, absoluteProgress) =>
          setActiveIndex(absoluteProgress)
        }
/>

@dohooo
Copy link
Owner

dohooo commented Oct 19, 2022

@dohooo I'm confused. Even using that example the index is only changed when the item has actually snapped and it's not immediate on swipe. Here's my code

<Carousel
        ref={carouselRef}
        pagingEnabled
        loop={false}
        mode='vertical-stack'
        snapEnabled
        modeConfig={{
          snapDirection: 'left',
          stackInterval: 15,
          rotateZDeg: 0,
          showLength: 2
        }}
        data={data}
        width={width}
        height={100}
        renderItem={renderItem}
        onProgressChange={(_, absoluteProgress) =>
          setActiveIndex(absoluteProgress)
        }
/>

This is the wrong usage. The usage of onProgressChange should refer to this.

And about reanimated value.

@RGDEV2022
Copy link

@dohooo I'm not fully understanding why we need to use a usesharedvalue to make this work and being in reanimated. IMO having a setIndex and the index passed in should be enough. Like how the snap-carousel library pagination works.
I'll look into this though thanks.

@dohooo
Copy link
Owner

dohooo commented Oct 19, 2022

@dohooo I'm not fully understanding why we need to use a usesharedvalue to make this work and being in reanimated. IMO having a setIndex and the index passed in should be enough. Like how the snap-carousel library pagination works.
I'll look into this though thanks.

#284

@dohooo
Copy link
Owner

dohooo commented Oct 25, 2022

Hey everyone, This problem was resolved in 3.1.1. Try it!~

Most case are in here.

@dohooo dohooo closed this as completed Oct 25, 2022
@dohooo dohooo changed the title Pagination issue with loop carousels Index incorrect when data length changed. Oct 25, 2022
@nightness
Copy link
Author

Hey everyone, This problem was resolved in 3.1.1. Try it!~

Most case are in here.

Thank You!!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants