Latest0.1.3
Homepagehttps://github.com/ChaselAn/SwipableCell
LicenseMIT
Platformsios 9.0, requires ARC
DependenciesTexture
Authors
  • A Reduser-based swipable cell
  • support UITableView
  • support ASTableNode from Texture

Requirements

  • Swift 4.1, iOS 9

Installation

  • With Cocoapods:
pod 'SoapBubble', '~> 0.1.3'
# Then, run the following command:
$ pod install

Example

SoapBubble

How to use

UITableView

  • tableView
class TestTableViewController: UIViewController, SwipeTableViewCellDelegate {

    private lazy var tableView = UITableView()

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView..swipableCellDelegate = self
    }

    func swipe_tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath) -> [SwipedAction] {
        let deleteAction = SwipedAction(title: "delete") { (_) in
            // delete
        }
        deleteAction.needConfirm = .custom(title: "confirm delete?")
        let unreadAction = SwipedAction(title: "unread") { (_) in
        }
        unreadAction.backgroundColor = .gray

        if indexPath.row % 3 == 0 {
            deleteAction.preferredWidth = 100
        }

        if indexPath.row % 2 == 1 {
            return [unreadAction, deleteAction]
        } else {
            return [deleteAction]
        }
    }

    func swipe_tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
}
  • cell
class DemoTableViewCell: SwipableCell {
    // do something
}
tableView.register(DemoTableViewCell.self, forCellReuseIdentifier: "DemoTableViewCell")

or

tableView.register(SwipableCell.self, forCellReuseIdentifier: "DemoTableViewCell")

ASTableNode

  • tableNode
import AsyncDisplayKit
extension TestASTableViewController: UIViewController, ASTableNodeSwipableDelegate {

    private lazy var tableNode = ASTableNode()

    override func viewDidLoad() {
        super.viewDidLoad()
        tableNode.swipableCellDelegate = self
    }

    public func swipe_tableNode(_ tableNode: ASTableNode, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }

    public func swipe_tableNode(_ tableNode: ASTableNode, editActionsOptionsForRowAt indexPath: IndexPath) -> [SwipedAction] {

        guard let cell = tableNode.nodeForRow(at: indexPath) as? TextureDemoCellNode else { return [] }
        let deleteAction = SwipedAction(title: "delete", backgroundColor: #colorLiteral(red: 1, green: 0.01568627451, blue: 0.3450980392, alpha: 1), titleColor: UIColor.white, titleFont: UIFont.systemFont(ofSize: 17, weight: .medium), preferredWidth: nil, handler: { (_) in
            // delete
        })
        deleteAction.needConfirm = .custom(title: "confirm delete?")

        let markAction: SwipedAction

        let markAsRead = SwipedAction(title: "unread", handler: { (_) in
            cell.hideSwipe(animated: true)
        })
        markAction = markAsRead

        markAction.backgroundColor = #colorLiteral(red: 0.8117647059, green: 0.8117647059, blue: 0.8117647059, alpha: 1)
        markAction.titleFont = UIFont.systemFont(ofSize: 17, weight: .medium)
        markAction.horizontalMargin = 24
        deleteAction.horizontalMargin = 24

        return [markAction, deleteAction]
    }
}
  • cellNode
class TextureDemoCellNode: SwipableCellNode {

    override init(tableNode: ASTableNode) {
        super.init(tableNode: tableNode)

        // do something

    }

    override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
        // layout
    }
}
extension TestASTableViewController: ASTableDataSource {

    func tableNode(_ tableNode: ASTableNode, nodeForRowAt indexPath: IndexPath) -> ASCellNode {
        let cell = TextureDemoCellNode(tableNode: tableNode)
        return cell
    }
}

or

extension TestASTableViewController: ASTableDataSource {

    func tableNode(_ tableNode: ASTableNode, nodeForRowAt indexPath: IndexPath) -> ASCellNode {
        let cell = SwipableCellNode(tableNode: tableNode)
        return cell
    }
}

Note

  • The current version is temporarily dependent on Texture, and later versions will be stripped out. Use on demand.

Latest podspec

{
    "name": "SoapBubble",
    "version": "0.1.3",
    "summary": "Let your cell slip like a soap",
    "homepage": "https://github.com/ChaselAn/SwipableCell",
    "license": "MIT",
    "authors": {
        "ChaselAn": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/ChaselAn/SoapBubble.git",
        "tag": "0.1.3"
    },
    "source_files": "SoapBubble/*.swift",
    "requires_arc": true,
    "dependencies": {
        "Texture": [
            "~> 2.6"
        ]
    }
}

Pin It on Pinterest

Share This