Skip to content

Commit

Permalink
support onSwipeStart event
Browse files Browse the repository at this point in the history
also don't zero the onWillBounceBack and onBouncedBack callbacks since they can be called multiple times.
  • Loading branch information
artald committed May 22, 2016
1 parent 87178aa commit 74140b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions ios/lib/SwipeViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @interface SwipeView : UIView <UIGestureRecognizerDelegate>
@property (nonatomic) BOOL changeAlpha;
@property (nonatomic) CGFloat bounceBackAnimDuration;
@property (nonatomic) CGFloat bounceBackAnimDamping;
@property (nonatomic, copy) RCTDirectEventBlock onSwipeStart;
@property (nonatomic, copy) RCTDirectEventBlock onWillBeSwipedOut;
@property (nonatomic, copy) RCTDirectEventBlock onSwipedOut;
@property (nonatomic, copy) RCTDirectEventBlock onWillBounceBack;
Expand Down Expand Up @@ -110,6 +111,12 @@ -(void)onPanGesture:(UIPanGestureRecognizer*)panGesture
}

[self cancelCurrentTouch];

NSString *directionString = ([panGesture velocityInView:self].x < 0) ? @"left" : @"right";
if (_onSwipeStart)
{
_onSwipeStart(@{@"direction": directionString});
}
}
else if(panGesture.state == UIGestureRecognizerStateChanged)
{
Expand Down Expand Up @@ -162,7 +169,6 @@ -(void)onPanGesture:(UIPanGestureRecognizer*)panGesture
if (_onWillBounceBack)
{
_onWillBounceBack(@{});
self.onWillBounceBack = nil;
}

[UIView animateWithDuration:self.bounceBackAnimDuration
Expand All @@ -181,7 +187,6 @@ -(void)onPanGesture:(UIPanGestureRecognizer*)panGesture
if (_onBouncedBack)
{
_onBouncedBack(@{});
self.onBouncedBack = nil;
}
}];
}
Expand All @@ -203,6 +208,7 @@ - (UIView *)view
RCT_REMAP_VIEW_PROPERTY(minPanToComplete, minPanToComplete, CGFloat)
RCT_REMAP_VIEW_PROPERTY(bounceBackAnimDuration, bounceBackAnimDuration, CGFloat)
RCT_REMAP_VIEW_PROPERTY(bounceBackAnimDamping, bounceBackAnimDamping, CGFloat)
RCT_REMAP_VIEW_PROPERTY(onSwipeStart, onSwipeStart, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(onWillBeSwipedOut, onWillBeSwipedOut, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(onSwipedOut, onSwipedOut, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(onWillBounceBack, onWillBounceBack, RCTDirectEventBlock)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/wix/react-native-swipe-view.git"
},
"version": "2.0.0",
"version": "2.0.1",
"description": "Native container view for enabling swipe actions (for example to enable swipe to delete and such)",
"nativePackage": true,
"bugs": {
Expand Down

0 comments on commit 74140b6

Please sign in to comment.