无法使用反应原生卡堆栈刷卡器正确检测卡索引?



我使用CardStack的onSwiped事件来检测卡索引,正如它在文档上所说的那样,它接收到了刷卡的索引,但这与我传递给的数据不是同一个索引。当我打印索引时,我意识到对于相同的卡索引更改,有人能帮忙吗?

我研究了包的实现,当CardStack的循环道具为true时,同一张卡的索引会发生变化,为了检测索引,我使用按钮左右滑动,并使用自定义索引跟踪循环道具为false的卡索引,这是默认值,对于任何可能遇到这个问题的人来说,这就是我所做的

const [cardIndex, setCardIndex] = useState(0);
// pass it to CardStack ref
const swiperRef = useRef();
const onLeftButtonClick = () => {
if(cardIndex > 0) {
setCardIndex(cardIndex - 1);
swiperRef.current.goBackFromRight();
}
}
const onRightButtonClick = () => {
// data used to render cards 
if(cardIndex < data.length - 1) {
setCardIndex(cardIndex + 1);
swiperRef.current.swipeLeft();
}
}

最新更新