alexbrillant / react-native-deck-swiper

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

Rerendering card resets Swiper to first card #74

Closed miclaus closed 7 years ago

miclaus commented 7 years ago

how can i rerender a card, but not reset the Swiper to the first card ?

consider the following within the render function:

const cardData = this.state.cardData
const myCards = map(cardData, (card, cardIndex) => {
  return (
    <CardComponent
      key={cardIndex}
      prop={card.prop}
      onEvent={this.onEvent}
    />
  )
})

return (
  <Swiper
    ref={swiper => this.swiper = swiper}
    cards={myCards}
    cardVerticalMargin={0}
    cardHorizontalMargin={0}
    infinite={true}
    renderCard={card => card}
    backgroundColor={'transparent'}
    verticalSwipe={false}
    onSwiped={() => false}
    onSwipedAll={() => false}
    onSwipedLeft={() => false}
    onSwipedRight={() => false}
  ></Swiper>
)
webraptor commented 7 years ago

Also set cardIndex on the Swiper from state. That way when you modify anything on the state, the deck will stay the same.

bispul commented 7 years ago

i have cardIndex on the Swiper from state but its still not working. The first card renders again immediately after you swipe that card. Can anyone help please?

webraptor commented 7 years ago

Ah, ok .. The bug is re-rendering and swiping will keep the second card to the second one in the original card deck, rather than the one you've swiped to so far ... We've experienced this issue for about a month now, just created the PR with the fix. https://github.com/alexbrillant/react-native-deck-swiper/pull/76/files

alexbrillant commented 7 years ago

@webraptor thanks nice work

bispul commented 6 years ago

Don't know why but i am still getting the issue. :(

yonahforst commented 6 years ago

@bispul I fixed my issue by adding cardIndex to the state and then incrementing it in the onSwiped callback

bispul commented 6 years ago

@yonahforst hey now its not reseting but after the cards are finished when you try to do anything in the swiper it again calls the respective methods. does anyone know what's wrong ?