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

Examples with HTTP loading #36

Open
leifg opened this issue Feb 7, 2021 · 2 comments
Open

Examples with HTTP loading #36

leifg opened this issue Feb 7, 2021 · 2 comments

Comments

@leifg
Copy link

leifg commented Feb 7, 2021

I absolutely love this library. It makes the swiping gesture super convenient.

I was wondering though if anyone ever achieved a loading additional parts of the stack from an external resource (load 10 cards initially, once you get to 2 or 3 cards, load the rest and add them to the "back").

For me unfortunately updating the stack seems to get in the way of the animation. whenever I call a setState in one of the callback function, the animation gets messed up.

I already try to make sure to just use useRef for the onSwipe callback and only set the new state in the onLeftScreen callback but it still seems kinda clunky.

What I'm doing right now is only fetching new cards once the whole stack has been depleted, that seems to work but it would be great if I could have an "endless" stack by loading new cards whenever the stack gets close to zero.

@3DJakob
Copy link
Owner

3DJakob commented Feb 15, 2021

@leifg Hey glad you like my module! Yes this problem has been very apparent when developing this module. For instance if you take a look at my advanced example you can see a very ugly work around for this using a global variable of which cards to be removed (https://github.com/3DJakob/react-tinder-card-demo/blob/master/src/examples/Advanced.js#L28). I did this to avoid rerenders while cards are animating.

With this in mind you can do a similar implementation. It is fine to modify the cards array as long as the user is not moving any cards and secondly there are no cards currently animating. This is problematic because although onLeftScreen might have happened the user might already have started moving the next one.

I might revisit this plugin in the future as I believe it would be possible to fix this in a smarter way but I don't have time for that right now unfortunately.

Another possible solution for your specific problem could be having two tinder card stacks with different state arrays on top of each other. As soon as the first one is depleted you could move it to the bottom and add new cards. This would probably solve your issue! An even better variant of this would probably be just rendering 2 cards at the time. As soon as one of them calls onLeftScreen just put it in the back with new card information.

I hope this helps! And if it does please reply here so I can see how you solved it. Good luck!

@msveshnikov
Copy link

msveshnikov commented Apr 13, 2022

Hi guys, I think I implemented endless loading quite well here: https://github.com/msveshnikov/swiper/blob/master/src/App.js

Demo: https://swiper.ml/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants