Skip to content
This repository has been archived by the owner on Feb 10, 2020. It is now read-only.

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

Open
dmoli opened this issue Aug 10, 2017 · 4 comments
Open

Comments

@dmoli
Copy link

dmoli commented Aug 10, 2017

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
Copy link

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

@Haasith-G
Copy link

Hi!
Do you have any updates on this issue?

@nlmarti4
Copy link

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

@josephecombs
Copy link

josephecombs commented Apr 14, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants