【问题标题】:send card data to onswiped function将卡数据发送到 onswiped 功能
【发布时间】:2020-02-07 10:47:37
【问题描述】:

我想将我刚刚刷过的卡的具体数据发送到'onswipe'函数。请帮忙!

我正在使用“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】:

    所以,读一点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>
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      相关资源
      最近更新 更多