Skip to content

Commit

Permalink
MGSwipeSettings.swipeBounceRate property
Browse files Browse the repository at this point in the history
  • Loading branch information
digal committed Sep 6, 2016
1 parent fbb01f1 commit c38afaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions MGSwipeTableCell/MGSwipeTableCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
/** If NO the swipe bounces will be disabled, the swipe motion will stop right after the button */
@property (nonatomic, assign) BOOL enableSwipeBounces;

/** Coefficient applied to cell movement in bounce zone. Set to value between 0.0 and 1.0
to make the cell 'resist' swiping after buttons are revealed. Default is 1.0 */
@property (nonatomic, assign) CGFloat swipeBounceRate;

@end


Expand Down
8 changes: 8 additions & 0 deletions MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ -(instancetype) init
self.offset = 0;
self.keepButtonsSwiped = YES;
self.enableSwipeBounces = YES;
self.swipeBounceRate = 1.0;
self.showAnimation = [[MGSwipeAnimation alloc] init];
self.hideAnimation = [[MGSwipeAnimation alloc] init];
self.stretchAnimation = [[MGSwipeAnimation alloc] init];
Expand Down Expand Up @@ -980,6 +981,13 @@ - (void)setSwipeOffset:(CGFloat) newOffset;

if(activeSettings.enableSwipeBounces) {
_swipeOffset = newOffset;

CGFloat maxUnbouncedOffset = sign * activeButtons.bounds.size.width;

if (sign > 0 && newOffset > maxUnbouncedOffset
|| sign < 0 && newOffset < maxUnbouncedOffset) {
_swipeOffset = maxUnbouncedOffset + (newOffset - maxUnbouncedOffset) * activeSettings.swipeBounceRate;
}
}
else {
CGFloat maxOffset = sign * activeButtons.bounds.size.width;
Expand Down

0 comments on commit c38afaa

Please sign in to comment.