alexbrillant / react-native-deck-swiper

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

Calling 'swipeRight' or 'swipeLeft' after reaching last index reverts to index 1 #124

Closed steventnorris-40AU closed 6 years ago

steventnorris-40AU commented 6 years ago

I have a setup like this:

<View style={SwipeStyles.topContainer}>
  <Swiper
    ref={(swiper) => this.swiper = swiper}
    cards={this.state.potentialMatches}
    renderCard={(card) => {
        return <SwipeCard {...card} />
    }}
    cardIndex={0}
    cardVerticalMargin={0}
    cardHorizontalMargin={0}
    backgroundColor={'transparent'}
    cardStyle={SwipeStyles.swiperCard}
    horizontalSwipe={true}
    verticalSwipe={false}
  />
</View>

 <View style={SwipeStyles.bottomContainer}>
  <Button type='outline' title='Nah' 
    style={SwipeStyles.rejectButton} 
     onPress={() => {
        this.swiper.swipeLeft()
    }}
  />
  <Button type='filled' title='Write' colors={[]} 
    style={SwipeStyles.acceptButton} 
    onPress={() => {
        this.swiper.swipeRight()
    }}
  />
</View>

If the last index has been reached (aka there are no more cards in the stack) and either of those buttons are pressed, the stack reverts back to index 1, with the full stack from index 1 to end. My assumption would be that if the last index has been reached, no more cards should be swipeable, regardless of the button being touched.

webraptor commented 6 years ago

Well, you have 2 options: fix this and disable the buttons in your code, or create a PR with a fix for all swipe events with and empty deck 👍

steventnorris-40AU commented 6 years ago

At this point, I've got some code in my button events that just check indexes off of your swipe component. It works, but I'm sure the code could be moved into your component itself to prevent the index jump. I'm not sure when I'll have time, but I'll try to do a PR if I can, see what I see.

webraptor commented 6 years ago

Was able to debug this and it looks like after the last swipe the deck doesn't trigger the swipedAll event.

webraptor commented 6 years ago

Fixed by https://github.com/alexbrillant/react-native-deck-swiper/pull/181