Skip to content

Commit

Permalink
Move allowsButtonWithDifferentWidth property to MGSwipeSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Nov 18, 2017
1 parent 9b7a262 commit 6d6fda3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion MGSwipeTableCell/MGSwipeTableCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
to make the cell 'resist' swiping after buttons are revealed. Default is 1.0 */
@property (nonatomic, assign) CGFloat swipeBounceRate;

// default is NO. Controls whether buttons with different width are allowed. Buttons are resized to have the same size by default.
@property (nonatomic) BOOL allowsButtonsWithDifferentWidth;

@end


Expand Down Expand Up @@ -241,7 +244,7 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
// default is NO. Controls whether multiple cells can be swiped simultaneously
@property (nonatomic) BOOL allowsMultipleSwipe;
// default is NO. Controls whether buttons with different width are allowed. Buttons are resized to have the same size by default.
@property (nonatomic) BOOL allowsButtonsWithDifferentWidth;
@property (nonatomic) BOOL allowsButtonsWithDifferentWidth DEPRECATED_MSG_ATTRIBUTE("Use MGSwipeSettings.allowsButtonsWithDifferentWidth instead");
//default is YES. Controls whether swipe gesture is allowed when the touch starts into the swiped buttons
@property (nonatomic) BOOL allowsSwipeWhenTappingButtons;
//default is YES. Controls whether swipe gesture is allowed in opposite directions. NO value disables swiping in opposite direction once started in one direction
Expand Down
12 changes: 7 additions & 5 deletions MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ @implementation MGSwipeButtonsView

#pragma mark Layout

-(instancetype) initWithButtons:(NSArray*) buttonsArray direction:(MGSwipeDirection) direction differentWidth:(BOOL) differentWidth swipeSettings:(MGSwipeSettings*) settings safeInset: (CGFloat) safeInset
-(instancetype) initWithButtons:(NSArray*) buttonsArray direction:(MGSwipeDirection) direction swipeSettings:(MGSwipeSettings*) settings safeInset: (CGFloat) safeInset
{
CGFloat containerWidth = 0;
CGSize maxSize = CGSizeZero;
Expand All @@ -84,7 +84,7 @@ -(instancetype) initWithButtons:(NSArray*) buttonsArray direction:(MGSwipeDirect
maxSize.width = MAX(maxSize.width, button.bounds.size.width);
maxSize.height = MAX(maxSize.height, button.bounds.size.height);
}
if (!differentWidth) {
if (!settings.allowsButtonsWithDifferentWidth) {
containerWidth = maxSize.width * buttonsArray.count + settings.buttonsDistance * (buttonsArray.count - 1);
}

Expand All @@ -104,7 +104,7 @@ -(instancetype) initWithButtons:(NSArray*) buttonsArray direction:(MGSwipeDirect
[btn removeTarget:nil action:@selector(mgButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; //Remove all targets to avoid problems with reused buttons among many cells
[btn addTarget:self action:@selector(mgButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
if (!differentWidth) {
if (!settings.allowsButtonsWithDifferentWidth) {
button.frame = CGRectMake(0, 0, maxSize.width, maxSize.height);
}
button.autoresizingMask = UIViewAutoresizingFlexibleHeight;
Expand Down Expand Up @@ -827,14 +827,16 @@ -(void) createSwipeViewIfNeeded

[self fetchButtonsIfNeeded];
if (!_leftView && _leftButtons.count > 0) {
_leftView = [[MGSwipeButtonsView alloc] initWithButtons:_leftButtons direction:MGSwipeDirectionLeftToRight differentWidth:_allowsButtonsWithDifferentWidth swipeSettings:_leftSwipeSettings safeInset:safeInsets.left];
_leftSwipeSettings.allowsButtonsWithDifferentWidth = _leftSwipeSettings.allowsButtonsWithDifferentWidth || _allowsButtonsWithDifferentWidth;
_leftView = [[MGSwipeButtonsView alloc] initWithButtons:_leftButtons direction:MGSwipeDirectionLeftToRight swipeSettings:_leftSwipeSettings safeInset:safeInsets.left];
_leftView.cell = self;
_leftView.frame = CGRectMake(-_leftView.bounds.size.width - safeInsets.left, _leftSwipeSettings.topMargin, _leftView.bounds.size.width, _swipeOverlay.bounds.size.height - _leftSwipeSettings.topMargin - _leftSwipeSettings.bottomMargin);
_leftView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
[_swipeOverlay addSubview:_leftView];
}
if (!_rightView && _rightButtons.count > 0) {
_rightView = [[MGSwipeButtonsView alloc] initWithButtons:_rightButtons direction:MGSwipeDirectionRightToLeft differentWidth:_allowsButtonsWithDifferentWidth swipeSettings:_rightSwipeSettings safeInset:safeInsets.right];
_rightSwipeSettings.allowsButtonsWithDifferentWidth = _rightSwipeSettings.allowsButtonsWithDifferentWidth || _allowsButtonsWithDifferentWidth;
_rightView = [[MGSwipeButtonsView alloc] initWithButtons:_rightButtons direction:MGSwipeDirectionRightToLeft swipeSettings:_rightSwipeSettings safeInset:safeInsets.right];
_rightView.cell = self;
_rightView.frame = CGRectMake(_swipeOverlay.bounds.size.width - safeInsets.right, _rightSwipeSettings.topMargin, _rightView.bounds.size.width, _swipeOverlay.bounds.size.height - _rightSwipeSettings.topMargin - _rightSwipeSettings.bottomMargin);
_rightView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
Expand Down

0 comments on commit 6d6fda3

Please sign in to comment.