gpt4 book ai didi

javascript - 在 native react 中从左向右滑动显示上一张卡片

转载 作者:行者123 更新时间:2023-11-29 23:26:24 26 4
gpt4 key购买 nike

我对 React Native 很陌生。我想在我使用过的应用程序中实现刷卡 react-native-tinder-swipe-cards .

是否可以在从左向右滑动时显示上一张卡片。即使我正在递减索引的值,也总是会显示下一张卡片,它位于数组的下一个索引处。

我现在正在尝试的是:

 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
})
}

}

}

最佳答案

肯定可以在现有库中添加一些功能,但由于时间限制,我将库从 react-native-tinder-swipe-cards. 切换到至 react-native-deck-swiper

在应用所有这些 Prop 后,我能够获得所需的功能

            <Swiper
ref={swiper => {
this.swiper = swiper
}}
goBackToPreviousCardOnSwipeRight={true}
showSecondCard={false}
onSwiped={this.onSwiped}
onTapCard={this.swipeLeft}
cards={this.state.cards}
cardIndex={id}
renderCard={this.renderCard}
verticalSwipe={false}
cardVerticalMargin={5}
cardHorizontalMargin={5}
onSwipedAll={this.onSwipedAllCards}
cardStyle={{height:520}}>
</Swiper>

关于javascript - 在 native react 中从左向右滑动显示上一张卡片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49097304/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com