alexandre-garrec / react-swipe-card

Tinder style swipe cards
https://alexandre-garrec.github.io/react-swipe-card
135 stars 79 forks source link

How I can trigger onSwipeLeft/onSwipeRight from a button click event? #12

Open dmoli opened 7 years ago

dmoli commented 7 years ago

Hi!

Like/Dislike card with a onSwipeLeft/onSwipeRight currently is ok.

But I want to Like/Dislike card with separate buttons (like a Tinder).

E.g: When I click the "Like Button" I need the card triggers the onSwipeRight. When I click the "Dislike Button" I need the card triggers the onSwipeLeft.

How can I do it?

Could I trigger the onSwipeLeft/onSwipeRight with a click event?

Thanks!

erinkshaw commented 6 years ago

I'm also curious how one would do this for keys (i.e. left key === left swipe; right key === right swipe)

Haasith-G commented 6 years ago

Hi! Do you have any updates on this issue?

nlmarti4 commented 5 years ago

I am also interested in doing something like this. Has anyone figured this out?

josephecombs commented 5 years ago

This has to be done with a ref.

In my example, I put the current swiper into a parent's state using a method I've defined, setCurrentSwiperRef (I use multiple swipers in the same page as people advance)

    <Cards
      onEnd={() => customOnEnd(props, 1)}
      className='master-root'
      alertRight={<CustomAlertRight />}
      alertLeft={<CustomAlertLeft />}
      ref={(instance) => { (typeof props.currentSwiperRef === 'undefined') && props.setCurrentSwiperRef(instance); }}
    >

And in some button elsewhere I can do:

      <button
        onClick={() => { props.currentSwiperRef.removeCard('Left', 0) }}
      >

The above utilizes the removeCard method defined here