From 0f695271ebbfaaabee53625a82c4980bbf3a6873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Esmer?= Date: Sat, 14 Dec 2024 13:36:42 +0300 Subject: [PATCH] refactor: rendering order of Swiper cards --- src/Swiper.tsx | 126 ++++++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/src/Swiper.tsx b/src/Swiper.tsx index 24774c3..b1857bb 100644 --- a/src/Swiper.tsx +++ b/src/Swiper.tsx @@ -111,66 +111,72 @@ const Swiper = ( [] ); - return data.map((item, index) => { - return ( - { - onSwipeRight?.(cardIndex); - }} - onSwipeLeft={(cardIndex) => { - onSwipeLeft?.(cardIndex); - }} - onSwipeTop={(cardIndex) => { - onSwipeTop?.(cardIndex); - }} - onSwipeBottom={(cardIndex) => { - onSwipeBottom?.(cardIndex); - }} - onSwipeStart={onSwipeStart} - onSwipeActive={onSwipeActive} - onSwipeEnd={onSwipeEnd} - swipeBackXSpringConfig={swipeBackXSpringConfig} - swipeBackYSpringConfig={swipeBackYSpringConfig} - swipeRightSpringConfig={swipeRightSpringConfig} - swipeLeftSpringConfig={swipeLeftSpringConfig} - swipeTopSpringConfig={swipeTopSpringConfig} - swipeBottomSpringConfig={swipeBottomSpringConfig} - > - {renderCard(item, index)} - - ); - }).reverse(); // to render cards in same hierarchy as their z-index + return data + .map((item, index) => { + return ( + { + onSwipeRight?.(cardIndex); + }} + onSwipeLeft={(cardIndex) => { + onSwipeLeft?.(cardIndex); + }} + onSwipeTop={(cardIndex) => { + onSwipeTop?.(cardIndex); + }} + onSwipeBottom={(cardIndex) => { + onSwipeBottom?.(cardIndex); + }} + onSwipeStart={onSwipeStart} + onSwipeActive={onSwipeActive} + onSwipeEnd={onSwipeEnd} + swipeBackXSpringConfig={swipeBackXSpringConfig} + swipeBackYSpringConfig={swipeBackYSpringConfig} + swipeRightSpringConfig={swipeRightSpringConfig} + swipeLeftSpringConfig={swipeLeftSpringConfig} + swipeTopSpringConfig={swipeTopSpringConfig} + swipeBottomSpringConfig={swipeBottomSpringConfig} + > + {renderCard(item, index)} + + ); + }) + .reverse(); // to render cards in same hierarchy as their z-index }; function fixedForwardRef(