Skip to content

Commit

Permalink
Add keepButtonsSwiped property to Swipe settings. Fix issue MortimerG…
Browse files Browse the repository at this point in the history
…oro#96: Spotify Cell expansion (revisited) MortimerGoro#96
  • Loading branch information
MortimerGoro committed Jul 14, 2015
1 parent 406acc7 commit f6a65d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions MGSwipeTableCell/MGSwipeTableCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ typedef NS_ENUM(NSInteger, MGSwipeExpansionLayout) {
/** Property to read or change swipe animation durations. Default value 0.3 */
@property (nonatomic, assign) CGFloat animationDuration;

/** If true the buttons are kept swiped when the threshold is reached and the user ends the gesture
* If false, the buttons are always hidden when the user ends the swipe gesture
*/
@property (nonatomic, assign) BOOL keepButtonsSwiped;

/** If true the table cell is not swiped, just the buttons **/
@property (nonatomic, assign) BOOL onlySwipeButtons;

Expand Down
8 changes: 5 additions & 3 deletions MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ -(instancetype) init
self.threshold = 0.5;
self.offset = 0;
self.animationDuration = 0.3;
self.keepButtonsSwiped = YES;
}
return self;
}
Expand Down Expand Up @@ -826,7 +827,8 @@ - (void)setSwipeOffset:(CGFloat) newOffset;
else {
[self showSwipeOverlayIfNeeded];
CGFloat swipeThreshold = sign < 0 ? _rightSwipeSettings.threshold : _leftSwipeSettings.threshold;
_targetOffset = offset > activeButtons.bounds.size.width * swipeThreshold ? activeButtons.bounds.size.width * sign : 0;
BOOL keepButtons = sign < 0 ? _rightSwipeSettings.keepButtonsSwiped : _leftSwipeSettings.keepButtonsSwiped;
_targetOffset = keepButtons && offset > activeButtons.bounds.size.width * swipeThreshold ? activeButtons.bounds.size.width * sign : 0;
}

BOOL onlyButtons = sign < 0 ? _rightSwipeSettings.onlySwipeButtons : _leftSwipeSettings.onlySwipeButtons;
Expand Down Expand Up @@ -1024,10 +1026,10 @@ -(void) panHandler: (UIPanGestureRecognizer *)gesture
CGFloat velocity = [_panRecognizer velocityInView:self].x;
CGFloat inertiaThreshold = 100.0; //points per second
if (velocity > inertiaThreshold) {
_targetOffset = _swipeOffset < 0 ? 0 : (_leftView ? _leftView.bounds.size.width : _targetOffset);
_targetOffset = _swipeOffset < 0 ? 0 : (_leftView && _leftSwipeSettings.keepButtonsSwiped ? _leftView.bounds.size.width : _targetOffset);
}
else if (velocity < -inertiaThreshold) {
_targetOffset = _swipeOffset > 0 ? 0 : (_rightView ? -_rightView.bounds.size.width : _targetOffset);
_targetOffset = _swipeOffset > 0 ? 0 : (_rightView && _rightSwipeSettings.keepButtonsSwiped ? -_rightView.bounds.size.width : _targetOffset);
}
_targetOffset = [self filterSwipe:_targetOffset];
[self setSwipeOffset:_targetOffset animated:YES completion:nil];
Expand Down

0 comments on commit f6a65d4

Please sign in to comment.