Skip to content

Commit

Permalink
Added disable swipe bounces
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninbiret committed Jan 13, 2016
1 parent 118d969 commit 0b2ee75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions MGSwipeTableCell/MGSwipeTableCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
/** If true the table cell is not swiped, just the buttons **/
@property (nonatomic, assign) BOOL onlySwipeButtons;

/** If true the swipe bounces will be disabled, the swipe motion will stop right after the button */
@property (nonatomic, assign) BOOL disableSwipeBounces;

@end


Expand Down
24 changes: 16 additions & 8 deletions MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ -(instancetype) init
self.threshold = 0.5;
self.offset = 0;
self.keepButtonsSwiped = YES;
self.disableSwipeBounces = NO;
self.showAnimation = [[MGSwipeAnimation alloc] init];
self.hideAnimation = [[MGSwipeAnimation alloc] init];
self.stretchAnimation = [[MGSwipeAnimation alloc] init];
Expand Down Expand Up @@ -934,12 +935,19 @@ -(void) updateState: (MGSwipeState) newState;

- (void)setSwipeOffset:(CGFloat) newOffset;
{
_swipeOffset = newOffset;

CGFloat sign = newOffset > 0 ? 1.0 : -1.0;
CGFloat offset = fabs(newOffset);

MGSwipeButtonsView * activeButtons = sign < 0 ? _rightView : _leftView;
MGSwipeSettings * activeSettings = sign < 0 ? _rightSwipeSettings : _leftSwipeSettings;

if(activeSettings.disableSwipeBounces) {
CGFloat maxOffset = sign * activeButtons.bounds.size.width;
_swipeOffset = sign > 0 ? MIN(newOffset, maxOffset) : MAX(newOffset, maxOffset);
} else {
_swipeOffset = newOffset;
}
CGFloat offset = fabs(_swipeOffset);


if (!activeButtons || offset == 0) {
if (_leftView)
[_leftView endExpansionAnimated:NO];
Expand All @@ -952,13 +960,13 @@ - (void)setSwipeOffset:(CGFloat) newOffset;
}
else {
[self showSwipeOverlayIfNeeded];
CGFloat swipeThreshold = sign < 0 ? _rightSwipeSettings.threshold : _leftSwipeSettings.threshold;
BOOL keepButtons = sign < 0 ? _rightSwipeSettings.keepButtonsSwiped : _leftSwipeSettings.keepButtonsSwiped;
CGFloat swipeThreshold = activeSettings.threshold;
BOOL keepButtons = activeSettings.keepButtonsSwiped;
_targetOffset = keepButtons && offset > activeButtons.bounds.size.width * swipeThreshold ? activeButtons.bounds.size.width * sign : 0;
}

BOOL onlyButtons = sign < 0 ? _rightSwipeSettings.onlySwipeButtons : _leftSwipeSettings.onlySwipeButtons;
_swipeView.transform = CGAffineTransformMakeTranslation(onlyButtons ? 0 : newOffset, 0);
BOOL onlyButtons = activeSettings.onlySwipeButtons;
_swipeView.transform = CGAffineTransformMakeTranslation(onlyButtons ? 0 : _swipeOffset, 0);

//animate existing buttons
MGSwipeButtonsView* but[2] = {_leftView, _rightView};
Expand Down

0 comments on commit 0b2ee75

Please sign in to comment.