-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Adjust index if data item is removed #157
Comments
Hi @Gerharddc, I totally get what you're after, but this might be tricky to implement. Would you mind providing me with a simple example that would serve as a starting point to work on this feature? Something based on the provided example maybe... |
@bd-arc I'll have to see about getting it integrated into the example but I can already give you the relevant code that I tested with yesterday:
The slightly strange syntax is just TypeScript. This code adds a new item just before you reach the end of the carousel and also removes an item for each one that it adds. If you run this and try to scroll to the next item after 1 has been 1 then it will suddenly jump another item ahead because the index of the item that you were looking at before the interaction has actually moved 1 down. If you were to remove more than 1 item at a time this effects just becomes worse. |
Hi @Gerharddc, I've gave your issue some thought, but I don't see an easy way to deal with it (particularly with the recent Do you have any suggestion about how this problem might be tackled? |
@bd-arc I can definitely notify the carousel of exactly how many items I will be removing before, after or during the change. In this way it should be able to adjust adjust the internal index accordingly. Unfortunately I am unfamiliar with the code-base and do not know if this is something that can easily be implemented. In theory I could get away with just a method to notify the carousel to adjust the index backwards by a certain amount. |
@Gerharddc Thanks for the feedback! I'll see if I can think of something that doesn't break the existing logic. FYI, index handling already consists of more than 100 lines of code... |
any progress on this? It looks like I ran into the same issue: when adding element to the |
I've been able to work around my issue by using |
Hi @m-vdb, I didn't have time to work on this issue lately, but if the problem is spreading I'll try to take a look at it shortly. Not before next week though, since I currently have major professional deadlines to meet ;-) |
having the same issue, when deleting the last item a blank slide was displayed until you started scrolling again. Solved it by adopting @m-vdb solution, but it feels hacky.
|
If use same data, or when the data length is 1 and we add data items, there will be buggy too, inspired by @raduflp , I use following hack code to treat these situations
|
Hey guys, I finally had time to dig deeper into the issue. I've tried different things, but I don't see any other solution than the one you've all came up with: to snap without animation to the relevant item when the data set is updated. With Still, if you have another idea of dealing with it, do not hesitate to share it! I'll gladly try to implement it ;-) |
Not sure why I did not think of this earlier, but I think we just need to pass a unique key with each item in the list. When the carousel receives new props, it can simply check which keys have disappeared in order to adjust its index automatically. Please correct me if I am wrong. |
@Gerharddc Well, that's an idea worth pursuing. I'll see if I can implement something along those lines. If anyone wants to jump in and submit a PR, do not hesitate ;-) |
Ran into this problem as well.
I think the right place in the code would be here.
However this is far from a viable solution. Implementing keys as suggested by @Gerharddc would solve the I tried testing a better implementation of this but ran into a VERY strange bug. When state/props update after mount While testing I ran into a bug in the code (I think), that overrides the |
This comment was marked as spam.
This comment was marked as spam.
experiencing the same issue, any update about this? |
sorry, but did you find any solution about this? @Gerharddc |
I want to use this component to let a user navigate through a (potentially endless) stream of items and as such I am adding new items to the data array as the user nears the end of the list and this works just perfectly. Obviously though I can't just keep adding items without removing older ones forever as this will exhaust memory at some point.
Removing items from the start of the data array seems to work pretty well except for the fact that it seems to act very strange with the index system. The problem is that the index doesn't change and after navigation there is a huge jump to the position of the old index+1. It would be nice if the component could automatically deal with this or provide me with a way to decrement the index without visually navigating.
The text was updated successfully, but these errors were encountered: