react-native-card-stack-swiper
react-native-card-stack-swiper copied to clipboard
this.swiper.goBackFrom[left/right/top/bottom] doesn't put last card back on top of stack
Whenever I swipe a card, then use the goBackFrom...() function, it doesn't put the last swiped card on top. Instead, it puts the card that is at the bottom of the stack on top. Any fixes? Cheers!
Try replace componentWillReceiveProps function in CardStack.js with following
componentWillReceiveProps(nextProps){ if (!this._isSameChildren(nextProps.children, this.props.children)) { this.setState({ cards: nextProps.children, cardA: nextProps.children[(this.state.topCard=='cardA')? this.state.sindex-2 : this.state.sindex-1], cardB: nextProps.children[(this.state.topCard=='cardB')? this.state.sindex-2 : this.state.sindex-1] }); } }
then add the comparison function
_isSameChildren(a, b) { if (a.length != b.length) return false; for (let i in a) { if (a[i].key != b[i].key) { return false } } return true }