alexbrillant / react-native-deck-swiper

tinder like react-native deck swiper
ISC License
1.56k stars 465 forks source link

Updating swiper cards re-render issues #19

Closed webraptor closed 7 years ago

webraptor commented 7 years ago

Updating Swiper cards sent as argument doesn't trigger cardIndex reset and neither does it trigger rendering of Swiper component. Steps to reproduce:

  1. Pass 5 cards to the Swiper during setup
  2. Swipe 1 or 2 cards of the Swiper
  3. Trigger an external action that causes state to change and to update the cards passed along at step 1
  4. Swiper doesn't reset and doesn't work properly

Possible fixes

  1. Add a method to update Swiper cards that will trigger chain reactions to reinitialize Swiper with proper paramater values
  2. Add a method to push new cards to Swiper that will trigger chain reactions so that proper paramater values are preserved and Swiper works correctly. This method could have a reset flag to achieve solution 1 above. This will allow updating the cards stack with new cards while users are swiping (IE: with data from push notifications, for example)
alexbrillant commented 7 years ago

I am not sure if I get your issue, but here is how to achieve lazy loading : https://github.com/alexbrillant/react-native-deck-swiper/issues/7

alexbrillant commented 7 years ago

What do you mean by updating swiper cards ? What kind of update ? What are you trying to do ? Perhaps, should I add a componentWillReceiveProps to update card indexes ? And, if so, what kind of behavior would you expect to happen ? @webraptor

webraptor commented 7 years ago

@alexbrillant yeap, more or less I am trying to achieve what you're referring to with componentWillReceiveProps. The issue was that cards payload gets updated externally form the swiper component, and if user has already swiped some cards the indexes get messed up if all cards are different (IE: original cards different than newly received ones, think of it as a complete change in a search). I'm already working on it, will be creating a PR within the next day...

With lazy loading it's another thing, since the cards are just pushed to the end of the stack and everything works smoothly.

alexbrillant commented 7 years ago

fixed in 1.3.3 !