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

React Native: update card issue #85

Open
jerry-inc opened this issue Feb 17, 2022 · 1 comment
Open

React Native: update card issue #85

jerry-inc opened this issue Feb 17, 2022 · 1 comment

Comments

@jerry-inc
Copy link

Hi,

I tried this library and it is really amazing. However, I am facing one critical issue, due to which I cant use it.

Platform: React Native: ios & android
Issue: On updating the data source, the tinder card switches back to card one.

Basically, what I am trying to do is; To show many cards with some static images initially, same as the example. but every card has a button to open the camera and capture a new image, which will then replace the static image. However, when I update the data source, the TinderCard switches back to card one.

I understand that state update rerenders the component, but I have tried to render every card individually in a separate state and still, I am facing this issue.

I even tried to save the image sources separately as a useRef, but still, when the image updates even in a single card, the whole deck resets and card one comes to the screen.

Kindly look into this issue.

@3DJakob
Copy link
Owner

3DJakob commented Oct 15, 2022

This is unfortunately a bit tricky problem to solve. The issue lies in the fact that if react would track all card positions live in states the animations would be laggy. Thus they are not kept in state. That means that they get reset once a re-render occurs.

One way of solving this is updating your data array once a card has left the screen. However, the problem with that solution is that if the user quickly starts moving the next card before the first leaves the dragged card instantly snaps back. However, if the user never is swiping cards while you change images then it is as simple a removing the cards that have left the screen when updating the images to the state.

If not you need to use multiple card data states or use global variables for your data. Look at the native advanced usage example it is native but the code should be pretty much identical on the web. It uses an implementation that allows for dynamically removing swiped cards using global variables. It's not exactly what you are trying to do but it tackles the same issue.

I hope that can be help. I think with the knowledge of how it works you should be able to fix it.

Side note:
In the future it could be useful to send x and y coordintes on the left screen event and then allow a position input that would allow the user to render them outside when re-rendering which would be nicer since the undo buttons would still work for those cards then.

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

2 participants