Swiftpack.co - Package - SwipeCellKit/SwipeCellKit

SwipeCellKit

Build Status Version Status Swift 5.0 license MIT Platform Carthage compatible Twitter

Swipeable UITableViewCell/UICollectionViewCell based on the stock Mail.app, implemented in Swift.

About

A swipeable UITableViewCell or UICollectionViewCell with support for:

  • Left and right swipe actions
  • Action buttons with: text only, text + image, image only
  • Haptic Feedback
  • Customizable transitions: Border, Drag, and Reveal
  • Customizable action button behavior during swipe
  • Animated expansion when dragging past threshold
  • Customizable expansion animations
  • Support for both UITableView and UICollectionView
  • Accessibility
  • Dark Mode

Background

Check out my blog post on how SwipeCellKit came to be.

Demo

Transition Styles

The transition style describes how the action buttons are exposed during the swipe.

Border

Drag

Reveal

Customized

Expansion Styles

The expansion style describes the behavior when the cell is swiped past a defined threshold.

None

Selection

Destructive

Customized

Requirements

  • Swift 5.0
  • Xcode 10.3+
  • iOS 9.0+

Installation

CocoaPods (recommended)

use_frameworks!

# Latest release in CocoaPods
pod 'SwipeCellKit'

# Get the latest on develop
pod 'SwipeCellKit', :git => 'https://github.com/SwipeCellKit/SwipeCellKit.git', :branch => 'develop'

# If you have NOT upgraded to Xcode 11, use the last Swift Xcode 10.X compatible release
pod 'SwipeCellKit', '2.6.0'

# If you have NOT upgraded to Swift 5.0, use the last Swift 4.2/Xcode 10.2 compatible release
pod 'SwipeCellKit', '2.5.4'

# If you have NOT upgraded to Swift 4.2, use the last non-swift 4.2 compatible release
pod 'SwipeCellKit', '2.4.3'

Carthage

github "SwipeCellKit/SwipeCellKit"

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/SwipeCellKit/SwipeCellKit", from: "2.7.1")
]

Documentation

Read the docs. Generated with jazzy. Hosted by GitHub Pages.

Usage for UITableView

Set the delegate property on SwipeTableViewCell:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! SwipeTableViewCell
    cell.delegate = self
    return cell
}

Adopt the SwipeTableViewCellDelegate protocol:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
    guard orientation == .right else { return nil }

    let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
        // handle action by updating model with deletion
    }

    // customize the action appearance
    deleteAction.image = UIImage(named: "delete")

    return [deleteAction]
}

Optionally, you can implement the editActionsOptionsForRowAt method to customize the behavior of the swipe actions:

func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
    var options = SwipeOptions()
    options.expansionStyle = .destructive
    options.transitionStyle = .border
    return options
}

Usage for UICollectionView

Set the delegate property on SwipeCollectionViewCell:

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! SwipeCollectionViewCell
    cell.delegate = self
    return cell
}

Adopt the SwipeCollectionViewCellDelegate protocol:

func collectionView(_ collectionView: UICollectionView, editActionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
    guard orientation == .right else { return nil }

    let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
        // handle action by updating model with deletion
    }

    // customize the action appearance
    deleteAction.image = UIImage(named: "delete")

    return [deleteAction]
}

Optionally, you can implement the editActionsOptionsForItemAt method to customize the behavior of the swipe actions:

func collectionView(_ collectionView: UICollectionView, editActionsOptionsForItemAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
    var options = SwipeOptions()
    options.expansionStyle = .destructive
    options.transitionStyle = .border
    return options
}

Transitions

Three built-in transition styles are provided by SwipeTransitionStyle:

  • .border: The visible action area is equally divide between all action buttons.
  • .drag: The visible action area is dragged, pinned to the cell, with each action button fully sized as it is exposed.
  • .reveal: The visible action area sits behind the cell, pinned to the edge of the table view, and is revealed as the cell is dragged aside.

See Customizing Transitions for more details on customizing button appearance as the swipe is performed.

Transition Delegate

Transition for a SwipeAction can be observered by setting a SwipeActionTransitioning on the transitionDelegate property. This allows you to observe what percentage is visible and access to the underlying UIButton for that SwipeAction.

Expansion

Four built-in expansion styles are provided by SwipeExpansionStyle:

  • .selection
  • .destructive (like Mail.app)
  • .destructiveAfterFill (like Mailbox/Tweetbot)
  • .fill

Much effort has gone into making SwipeExpansionStyle extremely customizable. If these built-in styles do not meet your needs, see Customizing Expansion for more details on creating custom styles.

The built-in .fill expansion style requires manual action fulfillment. This means your action handler must call SwipeAction.fulfill(style:) at some point during or after invocation to resolve the fill expansion. The supplied ExpansionFulfillmentStyle allows you to delete or reset the cell at some later point (possibly after further user interaction).

The built-in .destructive, and .destructiveAfterFill expansion styles are configured to automatically perform row deletion when the action handler is invoked (automatic fulfillment). Your deletion behavior may require coordination with other row animations (eg. inside beginUpdates and endUpdates). In this case, you can easily create a custom SwipeExpansionStyle which requires manual fulfillment to trigger deletion:

var options = SwipeTableOptions()
options.expansionStyle = .destructive(automaticallyDelete: false)

NOTE: You must call SwipeAction.fulfill(with style:) at some point while/after your action handler is invoked to trigger deletion. Do not call deleteRows directly.

let delete = SwipeAction(style: .destructive, title: nil) { action, indexPath in
    // Update model
    self.emails.remove(at: indexPath.row)
    action.fulfill(with: .delete)
}

Advanced

See the Advanced Guide for more details on customization.

Credits

Maintained by @mkurabi.

Showcase

We're interested in knowing who's using SwipeCellKit in their app. Please submit a pull request to add your app!

License

SwipeCellKit is released under an MIT License. See LICENSE for details.

Please provide attribution, it is greatly appreciated.

Github

link
Stars: 4937

Dependencies

Used By

Total: 0

Releases

2.7.1 - 2019-09-24 05:57:30

Added

  • Support for Xcode 10.3+ (#353)

2.7.0 - 2019-09-13 20:04:45

Added

  • Support for updated SPM (Swift Package Manager) for Xcode 11+ (#325)
  • Support for iOS 13 Dark Mode (#337)

Fixed

  • Fixed hit test issue related to hidden cells (#314)
  • Fixed cell reuse layout issue (#335)
  • Fixed issue where a deleted cell that was being cell reused has the contentView offset incorrectly. (#355)
  • Fixed issue where on iOS 13 UICollectionViewCell does not perform swipe animation. (#333)

2.6.0 - 2019-09-13 20:03:58

Added

  • SwipeCellKit is now using Swift 5

2.5.4 - 2019-03-27 14:46:43

Fixed

  • Fixed Carthage when building with Xcode 10.2 (#297)

2.5.2 - 2019-03-26 22:08:24

Fixed

  • Add support for Xcode 10.2 (#279, #283)
  • Compatibility with applications using Swift 5 (see Mail App Example)

2.5.1 - 2018-12-13 18:08:46

Fixed

  • Cells do not hide correctly when also using non-SwipeCollectionViewCell cells in UICollectionView. (#265)

2.5.0 - 2018-09-14 16:53:14

Fixed

  • Update to Swift 4.2 and Xcode 10 Support (#215)

2.4.3 - 2018-06-19 04:57:27

Fixed

  • Fix issue where swipe cell does not return to neutral position correctly when swipping cell very quickly (#215)

2.4.2 - 2018-06-07 18:01:45

Fixed

  • Fix swipe action position when rotating a UITableView/UICollectionView with safe area insets.
  • Fix issue where gesture cancellation causes swipe cell to remain in dragging state in a non-left, right or centre x position.
  • Fix issue where expansion may trigger when swiping in the expansion zone very quickly.

2.4.1 - 2018-05-30 10:04:49

Fixed

  • Fix issue with swipe action handler not being invoked correctly at all times (#204, #205)

2.4.0 - 2018-05-28 05:54:06

Added

  • UICollectionView support. You can now add swipe actions to a UICollectionViewCell by using the SwipeCollectionViewCell (#4)

2.3.2 - 2018-05-21 21:23:07

Fixed

  • Add default implementation for visibleRect(for tableView: UITableView) as its optional (#201)

2.3.1 - 2018-05-18 16:46:38

Fixed

  • Fix issue where swiping a cell does not work while another cell is open (#197)

2.3.0 - 2018-05-18 03:35:50

Added

  • Support for vertically centered swipe actions for tall cells. (#186)

Fixed

  • Resolved issue where touching cell in swipe expantion zone resulted in immediate cell expansion (#194)
  • Reselect swipped cell if it was previously selected (#58)

2.2.0 - 2018-04-11 17:08:41

Added

  • Swift 4.1 Support. (#181)
  • Allow mix use of only image or text label actions. (#139)

Fixed

  • Fix issue where multiple SwipeTableViewCells can be swipped simultaneously. (#57)

2.1.0 - 2018-03-19 04:55:40

Added

  • Add support for safeAreaInsets (i.e. iPhone X) (#159, #119)

Fixed

  • Update README to fix an error with how to fulfill a delete row operation
  • Fix crash related to UIAccessablilityCustomAction if no accessability text is set on action image, or action label. (#156)
  • Fix issue where SwipeActionButton.maximumButtonWidth is not respected when its value is below the default/computed minimumButtonWidth (#150)

2.0.1 - 2017-12-28 05:21:25

Fixed

  • Fix issue where swipe actions intermittently on iOS 11.2 were not displayed correctly when cell is swiped. (#126)

1.9.1 - 2017-10-06 20:17:15

Fixed

  • Fix issue related to pixel misalignment for action buttons. (#50)
  • Fix crash on iOS 10.0.0 where UIFeedbackGenerator crashed on non-haptic supported devices. (#51)
  • Fix issue related to iOS 11. SwipeCellKit was inadvertently enabling/disabling various gestures on UITableView, including system level ones in hopes of disabling 3D Touch on swiped UITableViewCells. Developers must now handle the disabling/enabling of 3D touch when cell is swiped with the aid of SwipeTableViewCellDelegate. (#48)

2.0.0 - 2017-10-06 20:16:11

Added

  • Add Swift 4 support
  • New highlightedTextColor property on SwipeAction. (#88)

Fixed

  • Fix issue where swipe actions intermittently were not displayed when cell is swiped. (#85)

1.9.0 - 2017-06-17 22:51:07

Added

  • Added highlighted background color for action button. (#52)

Fixed

  • Correctly setting the parents project to support iOS 9.0+. (#40)
  • Fix issue where using non-SwipeTableViewCell within a UITableView interfered with didSelectRowAtIndexPath. This was caused by the assumption all cells in a UITableView extend SwipeTableViewCell. (#37) (#43)
  • Add protection against superview in point(inside:) being nil and crashing. (#46)

1.8.0 - 2017-04-17 22:44:27

Added

  • New targetOverscrollElasticity property in SwipeExpansionStyle to support customization of elasticity when dragging past the expansion target. (#30)
  • New swipeOffset property and setSwipeOffset(_:animated:completion:) in SwipeTableViewCell to support programmatically setting the swipe offset. (#19)
  • Add support for relayout of action buttons if cell frame changes while swiped (ie. rotation/tableview resizing). Now that active/swiped SwipeTableViewCells no longer reset to center when the parent UITableView performs layout (#28), better support for UITableView frame/bounds changes are required. The UITableView frame/bounds may change during rotation or whenever its parent view frame changes. The SwipeActionsView was already using auto layout to resize appropriately, but its button (and wrapper) subviews were using constraints derived from the default autoresizingMask. This change ensures the SwipeActionButtonWrapperView flexes with its parent SwipeActionsView, and button subviews pin to the appropriate left/right side of their wrapper view depending on orientation.

Fixed

  • Fix issue where mask was not removed when using .reset style action fulfillment. (#27)
  • Fix to adjust the cell's new frame origin x value when it's already active. This ensures a swiped cell is not reset to center whenever the UITableView performs layout on it's cell subviews.

1.7.0 - 2017-04-01 19:06:03

Added

  • Support for iOS 9. Thanks to @DMCApps!
  • Showcase link in the README to track apps using the framework. Please submit a pull request to add your app!

Updated

  • The Advanced Customization section in the README and moved it to a separate file.
  • The Requirements section in the README to reflect iOS 9 support.

1.6.1 - 2017-03-29 16:30:10

Fixed

  • Issue where transitions are messed up when expansionStyle is set to nil.

1.6.0 - 2017-03-28 18:05:06

Added

  • Fully customizable expansion styles. See README documentation for more details. (#14)
  • SwipeTableViewDelegate delegate methods for willBeginEditingRowAt and didEndEditingRowAt. (#18)

Fixed

  • Removed action view cleanup when cell moved moved off UIWindow. Initially, this was added to prevent retain cycles caused by SwipeAction handlers capturing self. Instead, it should be left up to the implementor to use [weak self] in handler implementations or ensure the action view is hidden before dismissing/popping a temporary parent view controller. I've verified this behaves the same way as UITableViewRowAction. (#23)
  • Issue where the table view pan gesture was being disabled along with all other table view gestures when a cell was swiped. (#21)

1.5.0 - 2017-03-14 09:34:45

Fixed

  • Issue where the destructive action animation relied on the table view to animate covering the deleted cell with the cells below it in order for its height to appear to shrink. If the cell being deleted was the last row, or the remaining cells below were not tall enough, the height of the deleted cell would not appear to shrink. Fixed by adding a mask to cell and animate its height to zero. (#15)
  • Missing call to super.didMoveToSuperview causing accessory taps to be ignored. (#16)
  • The previous action button textColor fix to re-add also setting the tint color to the text color. The tint color effects button images rendered as template images.

Added

  • Ability to programmatically show swipe actions. (#13)
  • Support for action background effect. (#10)

1.4.0 - 2017-03-07 09:28:31

Fixed

  • The expansion threshold for selection-style was always 50% of the screen width regardless of if the action view width was larger.
  • Issue where the textColor property in SwipeAction was not being applied.

Added

  • Accessibility support. (#5)
  • New expansionDelegate property in SwipeTableOptions providing ability to customize expansion behavior. See the README and API documentation for more details.
  • New transitionDelegate property in SwipeAction providing ability to customize transition behavior of individual actions as the swipe gesture is performed. See the README and API documentation for more details. (#9)
  • Example app now lets you choose circular button style to demo the new transitionDelegate and expansionDelegate.

Updated

  • Internal SwipeActionButton layout to separate the background color from the actual UIButton

1.3.0 - 2017-02-23 13:24:41

Fixed

  • Active animations were not always stopped when a new pan gesture began.
  • Images are not aligned properly on buttons without a title. (#6)

Added

  • New options in SwipeTableOptions to for more layout customization. (#7)
  • Example app now lets you choose between buttons with title + image, title only, and image only

1.2.1 - 2017-02-20 13:49:55

Fixed

  • Call reset at the end of a destructive swipe to ensure the tableView gestures are re-enabled (#3).
  • Feedback was not being generated when swiping from non-centered state
  • SwipeTableViewCellDelegate compiler error in README example.

1.2.0 - 2017-02-19 10:48:16

Breaking

  • Update SwipeTableViewCellDelegate allowing editActionsForRowAt to return nil and prevent swiping in the supplied orientation (#2).

Added

  • Example app now lets you choose to disable swiping right.
  • Expose hideSwipe(animated:) to allow the cell to be programmatically hidden.

1.1.1 - 2017-02-15 11:42:51

Fixed

  • Memory leak in SwipeActionsView holding reference to actions causing a retain cycle.