Open nofacez opened 1 year ago
Why not just set an integer as a key
property on the Swiper
component and just increment it whenever onSwiped
fires?
Why not just set an integer as a
key
property on theSwiper
component and just increment it wheneveronSwiped
fires?
This was the much easier fix for me!
❗️ First of all, if you are updating the cards list dynamically (e.g. adding new cards when there are 5 cards left in the current stack) and you are still facing the issue when the list doesn't update, please, make sure you have the latest version of the package. This issue should be fixed there.
Now, let's talk about our patient. Swiper doesn't update state after all cards were swiped because it considers the stack is finished and it stops adding new cards to it. Here the part of the code responsible for this:
swipedAllCards is a state variable, that is being set here
So once it is set to
true
it won't ever change to false because that stack just stops rendering.How did I manage to fix it?
❗️DISCLAIMER: I don't think this is the best solution. This is why I've opened this issue, so we could find a more universal solution.
I've moved
swipedAllCards
property fromstate
toprops
because I think we can decide ourselves when the list is finished or not. I've also added aisLoading
prop to allow managing loading state of the swiper. To prevent Swiper from stopping rendering cards insidewhile
case I've addedCardListLoadingComponent
andCardListEmptyComponent
that are shown during the loading and empty state. Here is myrenderStack
function:And here is my
incrementCardIndex
function:After this refactoring I had a working Deck Swiper so I stopped looking for a more reliable and universal solution. We have a heavy backend request for the new stack of cards, so while the request is pending the
loading
props is set totrue
and loading component is shown. When backend stops sending new cards theswipedAllCards
is set totrue
and empty component is shown.