alexbrillant / react-native-deck-swiper

tinder like react-native deck swiper
ISC License
1.55k stars 461 forks source link

OnSwipedAll dont working #310

Open denisonfer opened 4 years ago

denisonfer commented 4 years ago

Hello, i have one project like tinder, and i am using functional components to do this, i have code below:

export default function Match({ navigation }) {
  const swipeRef = useRef();

  const [datas, setDatas] = useState([]);
  const [indexCard, setIndexCard] = useState(0);

  async function loadData() {
    try {
      const {
        data: { data },
      } = await api.get('interaction/near_users/', {
        headers: headerParams,
      });

      setDatas(data);
    } catch (error) {
      console.tron.log('error request api', error);
    }
  }

  useEffect(() => {
    loadData();
  }, [loading, modalVisible]);

  function onSwiped() {
    setIndexCard(indexCard + 1);
  }

  return (
    <Container>
      <SwiperContainer>
        <Swiper
          ref={swipeRef}
          infinite={false}
          cards={datas}
          cardsIndex={indexCard}
          renderCard={(card, index) => (
            <CardUser card={card} index={index} avatarUser={avatar} />
          )}
          onTapCard={(index) => handleDetalhe(index)}
          onSwiped={onSwiped}
          onSwipedAll={() => console.log( 'end cards data' ) }
          stackSize={2}
          stackScale={10}
          onSwipedLeft={(index) => {
            handleInteracao(0, index);
          }}
          onSwipedRight={(index) => handleInteracao(1, index)}
          onSwipedTop={(index) => handleInteracao(2, index)}
          disableBottomSwipe={true}
          animateOverlayLabelsOpacity={true}
          animateCardOpacity={true}
          backgroundColor={'transparent'}
          overlayLabels={{
            left: {
              title: 'NOPE',
              style: {
                label: {
                  backgroundColor: 'red',
                  color: '#fff',
                  fontSize: 24,
                },
                wrapper: {
                  flexDirection: 'column',
                  alignItems: 'flex-end',
                  justifyContent: 'flex-start',
                },
              },
            },
            right: {
              title: 'LIKE',
              style: {
                label: {
                  backgroundColor: 'green',
                  color: '#fff',
                  fontSize: 24,
                },
                wrapper: {
                  flexDirection: 'column',
                  alignItems: 'flex-start',
                  justifyContent: 'flex-start',
                },
              },
            },
          }}
        />
      </SwiperContainer>

      <ActionsMatch>
        <ButtonDontLike onPress={() => swipeRef.current.swipeLeft()}>
          <IconMatchButton
            source={require('../../assets/button-dislike/dislike-match.png')}
          />
        </ButtonDontLike>

        <ButtonSuperLike onPress={() => swipeRef.current.swipeTop()}>
          <IconMatchButton
            source={require('../../assets/button-superlike/superlike-match.png')}
          />
        </ButtonSuperLike>

        <ButtonLike onPress={() => swipeRef.current.swipeRight()}>
          <IconMatchButton
            source={require('../../assets/button-action-like/like-match.png')}
          />
        </ButtonLike>
      </ActionsMatch>
    </Container>
  );
}

the Problem: onSwipedCard dont active.. i have infinite cards, even without data... can help?

jacquesdev commented 4 years ago

OnSwipedAll wont get called when infinite is true

webraptor commented 4 years ago

OnSwipedAll wont get called when infinite is true

That's correct. Normally you do not reach the end of the deck when infinite is set true so there's no possible scenario where onSwipedAll will get called.

jacquesdev commented 4 years ago

For info L https://github.com/alexbrillant/react-native-deck-swiper/issues/324