-
Notifications
You must be signed in to change notification settings - Fork 465
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
Edit cards and update index #228
Comments
@pierregoutheraud don't remove it from the list. when you swipe, just move the card index |
@lightninglu10 Unfortunately it is not that easy and it is what I meant by "An obvious solution is just not mutating the cards prop." Also, moving the card index is done internally by the swiper. I am showing here an example but in my app the cards are stored in a redux state and I need to keep track of the swiped left cards so that next time it initializes it does not display the previously swiped left cards. |
@pierregoutheraud Did you find a solution to this? |
@pierregoutheraud @matthewfbenjamin I fail to see the reason why you would do what you're describing. Especially if your swiper is configured with infinite false. |
In my scenario what's happening is that I have two screens where users can make the same edits. One of the screens is the Swiper and the other is a list view. They both perform the same actions but I need parity across them. So when a user makes a change on the
I wonder if a good feature would be to feed an array of indexes to skip over since the Swiper already has a Some psuedocode would be:
So instead of changing the array that's fed into the Swiper the ListView (in my case, but could be any other screen that affects the array for other people), I'd keep track of a list of edited objects. I guess I could do this on my side also but using the |
@matthewfbenjamin What are you using for state management? |
We use redux and we are using the same state across the two views. I think the issue is that when you edit an item in the array (swipe right on the card) that will change the status of the item from |
If the item in the array is moved all-together the swiper will re-render and start from the beginning and you shouldn't have any issues. |
Yeah, it is moved, but that goes against the issue that was opened. I'm splicing one array and pushing to another array. The spliced array is the one being shown, though. |
That's because it's not really an issue. What @pierregoutheraud was describing is intended behaviour, not a bug within the swiper. |
I am following on #153 because there is something not clear to me about cardIndex prop.
Passing cardIndex re-renders the cards but it does not seem to fix the index problem.
My swiper initializes with a list [1, 2, 3].
As soon as I swiped card 1, I am removing it from the list.
(In my app, this is needed and is done through redux state)
Causing a re-render of the swiper with the updated list [2, 3].
The thing is that after the first swipe and the re-render, the swiper displays 3 instead of 2.
This is normal because the internal current card index incremented from 0 to 1, but I would like to get around that.
So I basically need the current card index to stay at 0 after the re-render and I do not see how this is possible with cardIndex prop... I tried setting it at 0 but it does not change anything.
An obvious solution is just not mutating the cards prop.
Another solution is setting a key={list.length} to the Swiper so that I re-mount the Swiper each time I swipe... which is not great.
Another solution is to prevent re-rendering of the swiper, so rendering once at the start, removing stuff from the cards and not re-rendering the swiper. The problem with that is that onSwiped only gives you back an index so you would have to manage the difference between the swiper index and your updated cards.
Would be cool to have cardIndex and cardData returned from onSwiped.
So how would you make that work ?
The text was updated successfully, but these errors were encountered: