【发布时间】:2018-08-12 07:57:38
【问题描述】:
我对本机反应很陌生。我想在我的应用程序中实现刷卡,因为我使用了react-native-tinder-swipe-cards。
是否可以在从左向右滑动时显示上一张卡片。即使我减少 index 的值,下一张卡片也会显示在数组的下一个索引处。
我现在正在尝试的是:
handleYup(card) {
console.log("yup",card)
//Alert.alert("Card",card.id+"");
this.setState({
cardYup: true
})
}
handleNope(card) {
console.log("nope")
//Alert.alert("Card", card.id + "");
this.setState({
cardNope: true
})
}
cardRemoved(index) {
if(this.state.cardYup){
index=index-2;
this.setState({
cardYup:false
})
}
else if (this.state.cardNope) {
//index = index +1
this.setState({
cardNope: false
})
}
console.log(`The index is ${index}`);
Alert.alert("Index", index+"");
let CARD_REFRESH_LIMIT = 1
if (this.state.cards.length - index <= CARD_REFRESH_LIMIT) {
console.log(`There are only ${this.state.cards.length - index - 1} cards left.`);
if (!this.state.outOfCards) {
//console.log(`Adding ${cards2.length} more cards`)
Alert.alert("No Cards","No morecards present")
this.setState({
outOfCards: true
})
}
}
}
【问题讨论】:
-
我不认为图书馆对此提供支持。但是您可以在该库中拥有自己的逻辑。它有一个名为
_goToPrevCard的方法,但它没有在任何地方使用,因此您可能需要在库本身中实现它,而不是从代码中调用它。