Skip to content

Commit

Permalink
[ADD] rebuildStackValues method and use it on onSwipedCallBacks method (
Browse files Browse the repository at this point in the history
  • Loading branch information
aanikid authored Jun 23, 2022
1 parent d678ca5 commit 0ac9267
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down

0 comments on commit 0ac9267

Please sign in to comment.