Giter Site home page Giter Site logo

Comments (6)

SuttonKyle avatar SuttonKyle commented on September 22, 2024 3

I've found that if you create a ref in your constructor, like:
this.swipeCardRef = React.createRef()
Then include ref={this.swipeCardRef} in the props to your SwipeCards component, you can call this.swipeCardRef.current._forceRightSwipe() and this.swipeCardRef.current._forceLeftSwipe() in your onPress functions to force the swipe animation

from react-native-tinder-swipe-cards.

SuttonKyle avatar SuttonKyle commented on September 22, 2024 2

Your code right now is calling the method on load instead of onPress. Try replacing {this.swipeCardRef.current._forceRightSwipe()} with {() => this.swipeCardRef.current._forceRightSwipe()}

Also, I forgot to mention that this will only show the animation, and won't actually call the handleYup function, so you will have to manually call that within the button as well. You may also need a way to bind the current card to the button, which I haven't implemented yet, but if you need any more help with that, I can get back to you once I've implemented it.

from react-native-tinder-swipe-cards.

michallapkowski avatar michallapkowski commented on September 22, 2024

Hey @SuttonKyle

Can you shed more light?

I have the following:

class Home extends React.Component {

  constructor(props) {
    super(props);
    this.swipeCardRef = React.createRef();
  }
//some code

  render() {
    return (
      <View>
      <SwipeCards
        cards={this.props.cards}
        ref={this.swipeCardRef}
        cardRemoved={this.cardRemoved.bind(this)}/>
//some code
          <TouchableOpacity style = {styles.buttons} onPress = {this.swipeCardRef.current._forceRightSwipe()}/>
       </View>

And I get the TypeError: TypeError: null is not an object (evaluating 'this.swipeCardRef.current._forceRightSwipe')

Can you help?

from react-native-tinder-swipe-cards.

pabloteari avatar pabloteari commented on September 22, 2024

That worked! Thanks

from react-native-tinder-swipe-cards.

zeeshaanl avatar zeeshaanl commented on September 22, 2024

Your code right now is calling the method on load instead of onPress. Try replacing {this.swipeCardRef.current._forceRightSwipe()} with {() => this.swipeCardRef.current._forceRightSwipe()}

Also, I forgot to mention that this will only show the animation, and won't actually call the handleYup function, so you will have to manually call that within the button as well. You may also need a way to bind the current card to the button, which I haven't implemented yet, but if you need any more help with that, I can get back to you once I've implemented it.

How could I bind the current card to the button?

Thanks!

from react-native-tinder-swipe-cards.

zeeshaanl avatar zeeshaanl commented on September 22, 2024

Your code right now is calling the method on load instead of onPress. Try replacing {this.swipeCardRef.current._forceRightSwipe()} with {() => this.swipeCardRef.current._forceRightSwipe()}
Also, I forgot to mention that this will only show the animation, and won't actually call the handleYup function, so you will have to manually call that within the button as well. You may also need a way to bind the current card to the button, which I haven't implemented yet, but if you need any more help with that, I can get back to you once I've implemented it.

How could I bind the current card to the button?

Thanks!

Figured it out, the card can be referred to using swipeCardRef.current.state.card

from react-native-tinder-swipe-cards.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.