Comments (6)
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.
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.
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.
That worked! Thanks
from react-native-tinder-swipe-cards.
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.
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 thehandleYup
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)
- When merging cards/adding new cards. Current Card Index is Reset to 0 HOT 1
- Swipe not reacting on yup, nope and maybe positions
- Is this repo maintained anymore?
- Each child Warning HOT 1
- Awesome script... Now, how can I make it loop in the same order (endlessly) ? HOT 1
- Previous image is visible for a short moment when using image url's HOT 2
- Index of Rendered Card
- android support ?
- Show previous card on left to right swipe
- How to change View Background HOT 1
- Undo the removed the card HOT 1
- React-Native-Swipeable-Cards, Forked & Updated HOT 2
- bug swipe animation when adding new cards after renderNoMoreCards HOT 3
- componentWillReceiveProps de
- Swipe cards inside Scroll view HOT 2
- ShowYup at the bottom of the screen HOT 1
- 'Animated: `useNativeDriver` was not specified. HOT 4
- while swipping a card left or right all the cards are swipped together
- THIS REPO IS DEAD! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-tinder-swipe-cards.