Skip to content

Commit

Permalink
Add nullable annotations. Improved support for Swift 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Oct 1, 2016
1 parent 3551705 commit 624586c
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 212 deletions.
32 changes: 16 additions & 16 deletions MGSwipeTableCell/MGSwipeButton.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MGSwipeTableCell is licensed under MIT license. See LICENSE.md file for more information.
* Copyright (c) 2014 Imanol Fernandez @MortimerGoro
* Copyright (c) 2016 Imanol Fernandez @MortimerGoro
*/

#import <UIKit/UIKit.h>
Expand All @@ -19,33 +19,33 @@
* Convenience block callback for developers lazy to implement the MGSwipeTableCellDelegate.
* @return Return YES to autohide the swipe view
*/
typedef BOOL(^MGSwipeButtonCallback)(MGSwipeTableCell * sender);
@property (nonatomic, strong) MGSwipeButtonCallback callback;
typedef BOOL(^ MGSwipeButtonCallback)(MGSwipeTableCell * _Nonnull cell);
@property (nonatomic, strong, nullable) MGSwipeButtonCallback callback;

/** A width for the expanded buttons. Defaults to 0, which means sizeToFit will be called. */
@property (nonatomic, assign) CGFloat buttonWidth;

/**
* Convenience static constructors
*/
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets callback:(MGSwipeButtonCallback) callback;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title backgroundColor:(nullable UIColor *) color;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title backgroundColor:(nullable UIColor *) color padding:(NSInteger) padding;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title backgroundColor:(nullable UIColor *) color insets:(UIEdgeInsets) insets;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title backgroundColor:(nullable UIColor *) color callback:(nullable MGSwipeButtonCallback) callback;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title backgroundColor:(nullable UIColor *) color padding:(NSInteger) padding callback:(nullable MGSwipeButtonCallback) callback;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title backgroundColor:(nullable UIColor *) color insets:(UIEdgeInsets) insets callback:(nullable MGSwipeButtonCallback) callback;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title icon:(nullable UIImage*) icon backgroundColor:(nullable UIColor *) color;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title icon:(nullable UIImage*) icon backgroundColor:(nullable UIColor *) color padding:(NSInteger) padding;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title icon:(nullable UIImage*) icon backgroundColor:(nullable UIColor *) color insets:(UIEdgeInsets) insets;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title icon:(nullable UIImage*) icon backgroundColor:(nullable UIColor *) color callback:(nullable MGSwipeButtonCallback) callback;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title icon:(nullable UIImage*) icon backgroundColor:(nullable UIColor *) color padding:(NSInteger) padding callback:(nullable MGSwipeButtonCallback) callback;
+(nonnull instancetype) buttonWithTitle:(nonnull NSString *) title icon:(nullable UIImage*) icon backgroundColor:(nullable UIColor *) color insets:(UIEdgeInsets) insets callback:(nullable MGSwipeButtonCallback) callback;

-(void) setPadding:(CGFloat) padding;
-(void) setEdgeInsets:(UIEdgeInsets)insets;
-(void) centerIconOverText;
-(void) centerIconOverTextWithSpacing: (CGFloat) spacing;
-(void) iconTintColor:(UIColor *)tintColor;
-(void) iconTintColor:(nullable UIColor *)tintColor;


@end
2 changes: 1 addition & 1 deletion MGSwipeTableCell/MGSwipeButton.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MGSwipeTableCell is licensed under MIT license. See LICENSE.md file for more information.
* Copyright (c) 2014 Imanol Fernandez @MortimerGoro
* Copyright (c) 2016 Imanol Fernandez @MortimerGoro
*/

#import "MGSwipeButton.h"
Expand Down
56 changes: 28 additions & 28 deletions MGSwipeTableCell/MGSwipeTableCell.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MGSwipeTableCell is licensed under MIT license. See LICENSE.md file for more information.
* Copyright (c) 2014 Imanol Fernandez @MortimerGoro
* Copyright (c) 2016 Imanol Fernandez @MortimerGoro
*/

#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -87,11 +87,11 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
@property (nonatomic, assign) CGFloat bottomMargin;

/** Animation settings when the swipe buttons are shown */
@property (nonatomic, strong) MGSwipeAnimation * showAnimation;
@property (nonatomic, strong, nonnull) MGSwipeAnimation * showAnimation;
/** Animation settings when the swipe buttons are hided */
@property (nonatomic, strong) MGSwipeAnimation * hideAnimation;
@property (nonatomic, strong, nonnull) MGSwipeAnimation * hideAnimation;
/** Animation settings when the cell is stretched from the swipe buttons */
@property (nonatomic, strong) MGSwipeAnimation * stretchAnimation;
@property (nonatomic, strong, nonnull) MGSwipeAnimation * stretchAnimation;

/** Property to read or change swipe animation durations. Default value 0.3 */
@property (nonatomic, assign) CGFloat animationDuration DEPRECATED_ATTRIBUTE;
Expand Down Expand Up @@ -126,11 +126,11 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
/** Size proportional threshold to trigger the expansion button. Default value 1.5 */
@property (nonatomic, assign) CGFloat threshold;
/** Optional expansion color. Expanded button's background color is used by default **/
@property (nonatomic, strong) UIColor * expansionColor;
@property (nonatomic, strong, nullable) UIColor * expansionColor;
/** Defines the layout of the expanded button **/
@property (nonatomic, assign) MGSwipeExpansionLayout expansionLayout;
/** Animation settings when the expansion is triggered **/
@property (nonatomic, strong) MGSwipeAnimation * triggerAnimation;
@property (nonatomic, strong, nonnull) MGSwipeAnimation * triggerAnimation;

/** Property to read or change expansion animation durations. Default value 0.2
* The target animation is the change of a button from normal state to expanded state
Expand All @@ -154,21 +154,21 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
* Delegate method to enable/disable swipe gestures
* @return YES if swipe is allowed
**/
-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell canSwipe:(MGSwipeDirection) direction fromPoint:(CGPoint) point;
-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell canSwipe:(MGSwipeDirection) direction DEPRECATED_ATTRIBUTE; //backwards compatibility
-(BOOL) swipeTableCell:(nonnull MGSwipeTableCell*) cell canSwipe:(MGSwipeDirection) direction fromPoint:(CGPoint) point;
-(BOOL) swipeTableCell:(nonnull MGSwipeTableCell*) cell canSwipe:(MGSwipeDirection) direction DEPRECATED_ATTRIBUTE; //backwards compatibility

/**
* Delegate method invoked when the current swipe state changes
@param state the current Swipe State
@param gestureIsActive YES if the user swipe gesture is active. No if the uses has already ended the gesture
**/
-(void) swipeTableCell:(MGSwipeTableCell*) cell didChangeSwipeState:(MGSwipeState) state gestureIsActive:(BOOL) gestureIsActive;
-(void) swipeTableCell:(nonnull MGSwipeTableCell*) cell didChangeSwipeState:(MGSwipeState) state gestureIsActive:(BOOL) gestureIsActive;

/**
* Called when the user clicks a swipe button or when a expandable button is automatically triggered
* @return YES to autohide the current swipe buttons
**/
-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell tappedButtonAtIndex:(NSInteger) index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion;
-(BOOL) swipeTableCell:(nonnull MGSwipeTableCell*) cell tappedButtonAtIndex:(NSInteger) index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion;
/**
* Delegate method to setup the swipe buttons and swipe/expansion settings
* Buttons can be any kind of UIView but it's recommended to use the convenience MGSwipeButton class
Expand All @@ -179,25 +179,25 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
* @param expansionSettings instance to configure button expansions (optional)
* @return Buttons array
**/
-(NSArray*) swipeTableCell:(MGSwipeTableCell*) cell swipeButtonsForDirection:(MGSwipeDirection)direction
swipeSettings:(MGSwipeSettings*) swipeSettings expansionSettings:(MGSwipeExpansionSettings*) expansionSettings;
-(nullable NSArray<UIView*>*) swipeTableCell:(nonnull MGSwipeTableCell*) cell swipeButtonsForDirection:(MGSwipeDirection)direction
swipeSettings:(nonnull MGSwipeSettings*) swipeSettings expansionSettings:(nonnull MGSwipeExpansionSettings*) expansionSettings;

/**
* Called when the user taps on a swiped cell
* @return YES to autohide the current swipe buttons
**/
-(BOOL) swipeTableCell:(MGSwipeTableCell *)cell shouldHideSwipeOnTap:(CGPoint) point;
-(BOOL) swipeTableCell:(nonnull MGSwipeTableCell *)cell shouldHideSwipeOnTap:(CGPoint) point;

/**
* Called when the cell will begin swiping
* Useful to make cell changes that only are shown after the cell is swiped open
**/
-(void) swipeTableCellWillBeginSwiping:(MGSwipeTableCell *) cell;
-(void) swipeTableCellWillBeginSwiping:(nonnull MGSwipeTableCell *) cell;

/**
* Called when the cell will end swiping
**/
-(void) swipeTableCellWillEndSwiping:(MGSwipeTableCell *) cell;
-(void) swipeTableCellWillEndSwiping:(nonnull MGSwipeTableCell *) cell;

@end

Expand All @@ -210,23 +210,23 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
@interface MGSwipeTableCell : UITableViewCell

/** optional delegate (not retained) */
@property (nonatomic, weak) id<MGSwipeTableCellDelegate> delegate;
@property (nonatomic, weak, nullable) id<MGSwipeTableCellDelegate> delegate;

/** optional to use contentView alternative. Use this property instead of contentView to support animated views while swiping */
@property (nonatomic, strong, readonly) UIView * swipeContentView;
@property (nonatomic, strong, readonly, nonnull) UIView * swipeContentView;

/**
* Left and right swipe buttons and its settings.
* Buttons can be any kind of UIView but it's recommended to use the convenience MGSwipeButton class
*/
@property (nonatomic, copy) NSArray * leftButtons;
@property (nonatomic, copy) NSArray * rightButtons;
@property (nonatomic, strong) MGSwipeSettings * leftSwipeSettings;
@property (nonatomic, strong) MGSwipeSettings * rightSwipeSettings;
@property (nonatomic, copy, nonnull) NSArray<UIView*> * leftButtons;
@property (nonatomic, copy, nonnull) NSArray<UIView*> * rightButtons;
@property (nonatomic, strong, nonnull) MGSwipeSettings * leftSwipeSettings;
@property (nonatomic, strong, nonnull) MGSwipeSettings * rightSwipeSettings;

/** Optional settings to allow expandable buttons */
@property (nonatomic, strong) MGSwipeExpansionSettings * leftExpansion;
@property (nonatomic, strong) MGSwipeExpansionSettings * rightExpansion;
@property (nonatomic, strong, nonnull) MGSwipeExpansionSettings * leftExpansion;
@property (nonatomic, strong, nonnull) MGSwipeExpansionSettings * rightExpansion;

/** Readonly property to fetch the current swipe state */
@property (nonatomic, readonly) MGSwipeState swipeState;
Expand All @@ -248,17 +248,17 @@ typedef NS_ENUM(NSInteger, MGSwipeEasingFunction) {
@property (nonatomic) BOOL touchOnDismissSwipe;

/** Optional background color for swipe overlay. If not set, its inferred automatically from the cell contentView */
@property (nonatomic, strong) UIColor * swipeBackgroundColor;
@property (nonatomic, strong, nullable) UIColor * swipeBackgroundColor;
/** Property to read or change the current swipe offset programmatically */
@property (nonatomic, assign) CGFloat swipeOffset;

/** Utility methods to show or hide swipe buttons programmatically */
-(void) hideSwipeAnimated: (BOOL) animated;
-(void) hideSwipeAnimated: (BOOL) animated completion:(void(^)(BOOL finished)) completion;
-(void) hideSwipeAnimated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated;
-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated completion:(void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animated: (BOOL) animated completion:(void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animation: (MGSwipeAnimation *) animation completion:(void(^)(BOOL finished)) completion;
-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animation: (nonnull MGSwipeAnimation *) animation completion:(nullable void(^)(BOOL finished)) completion;
-(void) expandSwipe: (MGSwipeDirection) direction animated: (BOOL) animated;

/** Refresh method to be used when you want to update the cell contents while the user is swiping */
Expand Down
5 changes: 2 additions & 3 deletions MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MGSwipeTableCell is licensed under MIT license. See LICENSE.md file for more information.
* Copyright (c) 2014 Imanol Fernandez @MortimerGoro
* Copyright (c) 2016 Imanol Fernandez @MortimerGoro
*/

#import "MGSwipeTableCell.h"
Expand Down Expand Up @@ -984,8 +984,7 @@ - (void)setSwipeOffset:(CGFloat) newOffset;

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

if (sign > 0 && newOffset > maxUnbouncedOffset
|| sign < 0 && newOffset < maxUnbouncedOffset) {
if ((sign > 0 && newOffset > maxUnbouncedOffset) || (sign < 0 && newOffset < maxUnbouncedOffset)) {
_swipeOffset = maxUnbouncedOffset + (newOffset - maxUnbouncedOffset) * activeSettings.swipeBounceRate;
}
}
Expand Down
17 changes: 15 additions & 2 deletions demo/MailAppDemoSwift/MailAppDemoSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@
TargetAttributes = {
11E203631A1A9B440084A446 = {
CreatedOnToolsVersion = 6.1;
LastSwiftMigration = 0810;
};
11E203781A1A9B440084A446 = {
CreatedOnToolsVersion = 6.1;
DevelopmentTeam = 4W4992Q3W8;
LastSwiftMigration = 0810;
TestTargetID = 11E203631A1A9B440084A446;
};
};
Expand Down Expand Up @@ -305,7 +308,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -342,7 +345,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -354,21 +357,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = MailAppDemoSwift/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = MailAppDemoSwift/ObjCBridgingHeader.h;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
11E203851A1A9B440084A446 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = MailAppDemoSwift/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = MailAppDemoSwift/ObjCBridgingHeader.h;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -387,6 +398,7 @@
INFOPLIST_FILE = MailAppDemoSwiftTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MailAppDemoSwift.app/MailAppDemoSwift";
};
name = Debug;
Expand All @@ -402,6 +414,7 @@
INFOPLIST_FILE = MailAppDemoSwiftTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MailAppDemoSwift.app/MailAppDemoSwift";
};
name = Release;
Expand Down
Loading

0 comments on commit 624586c

Please sign in to comment.