отправить данные карты в функцию onswiped - PullRequest
0 голосов
/ 07 февраля 2020

Я хочу отправить указанные c данные карточки, которую я только что пролистал, в функцию «onswiped». ПОМОГИТЕ ПОЖАЛУЙСТА!

Я использую 'Reaction-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>

}

1 Ответ

0 голосов
/ 07 февраля 2020

Итак, читая немного документы , вы должны отправить индекс, полученный при вызове, в вашу функцию, что-то вроде:

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>

}
...