From 2a75602b26387c4801076a777e4fac62cdc3d29c Mon Sep 17 00:00:00 2001 From: aanikid Date: Fri, 15 Oct 2021 13:53:02 +0200 Subject: [PATCH] =?UTF-8?q?=C3=83[ADD]=20rebuildStackValues=20method=20and?= =?UTF-8?q?=20use=20it=20on=20onSwipedCallBacks=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Swiper.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Swiper.js b/Swiper.js index edcc1406..3bc90ff5 100644 --- a/Swiper.js +++ b/Swiper.js @@ -539,11 +539,20 @@ class Swiper extends Component { this.setCardIndex(newCardIndex, false) } } + rebuildStackValues = () => { + const stackPositionsAndScales = {} + const { stackSize, stackSeparation, stackScale } = this.props + for (let position = 0; position < stackSize; position++) { + stackPositionsAndScales[`stackPosition${position}`] = new Animated.Value(stackSeparation * position) + stackPositionsAndScales[`stackScale${position}`] = new Animated.Value((100 - stackScale * position) * 0.01) + } + return stackPositionsAndScales + } onSwipedCallbacks = (swipeDirectionCallback) => { const previousCardIndex = this.state.firstCardIndex this.props.onSwiped(previousCardIndex, this.state.cards[previousCardIndex]) - + this.setState(this.rebuildStackValues) if (swipeDirectionCallback) { swipeDirectionCallback(previousCardIndex, this.state.cards[previousCardIndex]) }