mirror of
https://github.com/zhigang1992/react-native-card-stack-swiper.git
synced 2026-04-30 05:05:46 +08:00
remove duplicate callbacks. call with actual index.
This commit is contained in:
24
CardStack.js
24
CardStack.js
@@ -77,12 +77,10 @@ export default class CardStack extends Component {
|
|||||||
const swipeDirection = (gestureState.dy < 0) ? height * -1 : height;
|
const swipeDirection = (gestureState.dy < 0) ? height * -1 : height;
|
||||||
if(swipeDirection < 0 && !disableTopSwipe)
|
if(swipeDirection < 0 && !disableTopSwipe)
|
||||||
{
|
{
|
||||||
this.props.onSwipedTop(sindex);
|
|
||||||
this._nextCard('top', gestureState.dx, swipeDirection, 200);
|
this._nextCard('top', gestureState.dx, swipeDirection, 200);
|
||||||
}
|
}
|
||||||
else if (!disableBottomSwipe)
|
else if (!disableBottomSwipe)
|
||||||
{
|
{
|
||||||
this.props.onSwipedBottom(sindex);
|
|
||||||
this._nextCard('bottom', gestureState.dx, swipeDirection, 200);
|
this._nextCard('bottom', gestureState.dx, swipeDirection, 200);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -101,7 +99,6 @@ export default class CardStack extends Component {
|
|||||||
}
|
}
|
||||||
else if(!disableRightSwipe)
|
else if(!disableRightSwipe)
|
||||||
{
|
{
|
||||||
this.props.onSwipedRight(sindex);
|
|
||||||
this._nextCard('right', swipeDirection, gestureState.dy, 200);
|
this._nextCard('right', swipeDirection, gestureState.dy, 200);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -266,28 +263,27 @@ export default class CardStack extends Component {
|
|||||||
_nextCard(direction, x, y, duration=400){
|
_nextCard(direction, x, y, duration=400){
|
||||||
const { verticalSwipe, horizontalSwipe } = this.props;
|
const { verticalSwipe, horizontalSwipe } = this.props;
|
||||||
const { sindex, cards, topCard } = this.state;
|
const { sindex, cards, topCard } = this.state;
|
||||||
|
const index = sindex-2
|
||||||
if((sindex-2) < cards.length){
|
if((index) < cards.length){
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case 'left':
|
case 'left':
|
||||||
this.props.onSwipedLeft();
|
this.props.onSwipedLeft(index);
|
||||||
this.state.cards[sindex-2].props.onSwipedLeft();
|
this.state.cards[index].props.onSwipedLeft();
|
||||||
break;
|
break;
|
||||||
case 'right':
|
case 'right':
|
||||||
this.props.onSwipedRight();
|
this.props.onSwipedRight(index);
|
||||||
this.state.cards[sindex-2].props.onSwipedRight();
|
this.state.cards[index].props.onSwipedRight();
|
||||||
break;
|
break;
|
||||||
case 'top':
|
case 'top':
|
||||||
this.props.onSwipedTop();
|
this.props.onSwipedTop(index);
|
||||||
this.state.cards[sindex-2].props.onSwipedTop();
|
this.state.cards[index].props.onSwipedTop();
|
||||||
break;
|
break;
|
||||||
case 'bottom':
|
case 'bottom':
|
||||||
this.props.onSwipedBottom();
|
this.props.onSwipedBottom(index);
|
||||||
this.state.cards[sindex-2].props.onSwipedBottom();
|
this.state.cards[index].props.onSwipedBottom();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
Animated.spring(
|
Animated.spring(
|
||||||
this.state.dragDistance,
|
this.state.dragDistance,
|
||||||
|
|||||||
Reference in New Issue
Block a user