将卡数据发送到交换功能

问题描述 投票:0回答:1

我想将我刚刚刷过的卡的特定数据发送到'不刷卡'功能。请帮助!

我正在使用'react-native-deck-swiper';

onSwiped = (card, type) => {
  console.log(`on swiped ${type}`);
  console.log(card);
}

render() {
const search = this.props.search
<Swiper
      ref={swiper => {
        this.swiper = swiper
      }}
      onSwipedLeft={() => this.onSwiped(card, 'Not')}
      onSwipedRight={() => this.onSwiped(card, 'Favorite')}
      onSwipedTop={() => this.onSwiped(card, 'SUPER')}
      animateCardOpacity
      containerStyle={styles.container}
      cards={search}
      renderCard={card => <Card card={card}/>}
      cardIndex={this.state.cardIndex}
      cardVerticalMargin={80}
      onSwipedAll={this.onSwipedAllCards}
      stackSeparation={15}
      backgroundColor="white"
      stackSize={search.length > 3 ? 3 : 1}
      ....
    />
  </View>

}
reactjs react-native swipe swiper
1个回答
0
投票

所以,读一点docs,您必须将调用中收到的索引发送给您的函数,例如:

onSwiped = (index, type) => { //change args to receive index instead
  console.log(`on swiped ${type}`);
  console.log(this.props.search[index]);
}

render() {
const search = this.props.search
<Swiper
      ref={swiper => {
        this.swiper = swiper
      }}
      onSwipedLeft={(i) => this.onSwiped(i, 'Not')}
      onSwipedRight={(i) => this.onSwiped(i, 'Favorite')}
      onSwipedTop={(i) => this.onSwiped(i, 'SUPER')}
      animateCardOpacity
      containerStyle={styles.container}
      cards={search}
      renderCard={card => <Card card={card}/>}
      cardIndex={this.state.cardIndex}
      cardVerticalMargin={80}
      onSwipedAll={this.onSwipedAllCards}
      stackSeparation={15}
      backgroundColor="white"
      stackSize={search.length > 3 ? 3 : 1}
      ....
    />
  </View>

}
© www.soinside.com 2019 - 2024. All rights reserved.