From 093ae411c79c1dc80ea9a1c73b9e520742c32d45 Mon Sep 17 00:00:00 2001 From: Dani Akash Date: Mon, 22 Oct 2018 18:13:05 +0530 Subject: [PATCH 1/2] add onSwipeStart and onSwipeEnd event callbacks --- CardStack.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CardStack.js b/CardStack.js index bbae6a9..bec0f54 100644 --- a/CardStack.js +++ b/CardStack.js @@ -61,6 +61,7 @@ export default class CardStack extends Component { return Math.sqrt(Math.pow(gestureState.dx, 2) + Math.pow(gestureState.dy, 2)) > 10 }, //(parseInt(gestureState.dx) !== 0 && parseInt(gestureState.dy) !== 0), onPanResponderGrant: (evt, gestureState) => { + this.props.onSwipeStart(); this.setState({ touchStart: new Date().getTime() }); }, onPanResponderMove: (evt, gestureState) => { @@ -72,7 +73,7 @@ export default class CardStack extends Component { }, onPanResponderTerminationRequest: (evt, gestureState) => true, onPanResponderRelease: (evt, gestureState) => { - + this.props.onSwipeEnd(); const currentTime = new Date().getTime(); const swipeDuration = currentTime-this.state.touchStart; const { sindex } = this.state; @@ -441,6 +442,8 @@ CardStack.propTypes = { secondCardZoom: PropTypes.number, loop: PropTypes.bool, renderNoMoreCards: PropTypes.func, + onSwipeStart: PropTypes.func, + onSwipeEnd: PropTypes.func, onSwiped: PropTypes.func, onSwipedLeft: PropTypes.func, onSwipedRight:PropTypes.func, @@ -469,6 +472,8 @@ CardStack.defaultProps = { secondCardZoom: 0.95, loop: false, renderNoMoreCards: () => { return (No More Cards)}, + onSwipeStart: () => null, + onSwipeEnd: () => null, onSwiped: () => {}, onSwipedLeft: () => {}, onSwipedRight: () => {}, From 3ef0e679bbd38d311a39e40301f5d143796aece5 Mon Sep 17 00:00:00 2001 From: Dani Akash Date: Tue, 23 Oct 2018 11:50:30 +0530 Subject: [PATCH 2/2] update doc for onSwipeStart and onSwipeEnd events --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5c94d4b..9c1aa81 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ import CardStack, { Card } from 'react-native-card-stack-swiper'; ## CardStack events | Props | type | description | | ----------------- | ------------- | --------------------------- | +| onSwipeStart | func | function to be called when a card swipe starts | +| onSwipeEnd | func | function to be called when a card swipe ends (card is released) | | onSwiped | func | function to be called when a card is swiped. it receives the swiped card index | | onSwipedLeft | func | function to be called when a card is swiped left. it receives the swiped card index | | onSwipedRight | func | function to be called when a card is swiped right. it receives the swiped card index |