Javascript 在本机中从左向右滑动显示上一张卡

Javascript 在本机中从左向右滑动显示上一张卡,javascript,react-native,Javascript,React Native,我是个新来的本地人。我想在我的应用程序中为我使用过的应用程序实现刷卡 从左向右刷卡时是否可以显示以前的卡。即使我正在递减索引的值,也会始终显示阵列下一个索引处的下一张卡 我现在正在尝试的是: handleYup(card) { console.log("yup",card) //Alert.alert("Card",card.id+""); this.setState({ cardYup: true }) } handleNope(card)

我是个新来的本地人。我想在我的应用程序中为我使用过的应用程序实现刷卡

从左向右刷卡时是否可以显示以前的卡。即使我正在递减索引的值,也会始终显示阵列下一个索引处的下一张卡

我现在正在尝试的是:

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

    }

}
handleYup(卡片){
控制台日志(“是的”,卡片)
//Alert.Alert(“Card”,Card.id+”);
这是我的国家({
卡迪普:是的
})
}
手提电话(卡){
console.log(“nope”)
//Alert.Alert(“Card”,Card.id+”);
这是我的国家({
卡德诺:是的
})
}
已移除卡片(索引){
if(this.state.cardYup){
指数=指数-2;
这是我的国家({
卡迪普:错
})
}
else if(this.state.cardnop){
//索引=索引+1
这是我的国家({
卡德诺:错
})
}
log(`index是${index}`);
警报。警报(“索引”,索引+”);
让卡刷新限制=1

如果(this.state.cards.length-index可以肯定地在现有库中添加一些功能,但由于时间限制,我将库从切换到

在应用了所有这些道具之后,我能够获得想要的功能

            <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>
{
this.swiper=swiper
}}
goBackToPreviousCardOnSwipeRight={true}
showSecondCard={false}
onsweep={this.onsweep}
onTapCard={this.swipeLeft}
cards={this.state.cards}
cardIndex={id}
renderCard={this.renderCard}
垂直滑动={false}
cardVerticalMargin={5}
cardHorizontalMargin={5}
onswipdall={this.onswipdallcards}
cardStyle={{高度:520}}>

我认为库不支持这一点。但您可以在该库中拥有自己的逻辑。它有一个名为
\u goToPrevCard
的方法,但它没有在任何地方使用,所以您可能需要在库本身中实现它,而不是从代码中调用它。