Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom cell class #21

Merged
merged 6 commits into from Jul 29, 2019
Merged

Custom cell class #21

merged 6 commits into from Jul 29, 2019

Conversation

ra1028
Copy link
Owner

@ra1028 ra1028 commented May 16, 2019

Checklist

Description

Make Carbon enable to use custom cell subclass for the container of component.

Sample with SwipeCellKit.

extension SwipeTableViewCell: ComponentRenderable {}

final class SwipeCellKitTodoAdapter: UITableViewAdapter, SwipeTableViewCellDelegate {
    override func cellRegistration(tableView: UITableView, indexPath: IndexPath, node: CellNode) -> CellRegistration {
        return CellRegistration(class: SwipeTableViewCell.self)
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = super.tableView(tableView, cellForRowAt: indexPath) as! SwipeTableViewCell
        cell.delegate = self
        cell.selectionStyle = .none
        return cell
    }

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
        guard let deletable = cellNode(at: indexPath).component(as: Deletable.self), orientation == .right else {
            return nil
        }

        let deleteAction = SwipeAction(style: .destructive, title: nil) { action, _ in
            deletable.delete()
            action.fulfill(with: .delete)
        }

        deleteAction.image = #imageLiteral(resourceName: "Trash")
        return [deleteAction]
    }
}

Related Issue

#10

Motivation and Context

Users want to add an ability to customize cell, header or footer behavior related to {UITableView / UICollectionView}.
That's because to coexist Carbon and external libraries such as SwipeCellKit.
It also allows the user to have a more flexible implementation that isn't restricted by Carbon.

Impact on Existing Code

Many breaking changes are made to provide more flexible API.

Sources/Adapters/UICollectionViewAdapter.swift Outdated Show resolved Hide resolved
Sources/Adapters/UICollectionViewAdapter.swift Outdated Show resolved Hide resolved
Examples/Example-iOS/Podfile Show resolved Hide resolved
Examples/Example-iOS/Gemfile Show resolved Hide resolved
Sources/Adapters/UICollectionViewAdapter.swift Outdated Show resolved Hide resolved
Sources/Adapters/UICollectionViewAdapter.swift Outdated Show resolved Hide resolved
Examples/Example-iOS/Podfile Show resolved Hide resolved
Examples/Example-iOS/Gemfile Show resolved Hide resolved
@ra1028 ra1028 force-pushed the custom-cell-class branch 2 times, most recently from 00b15a3 to 5ce2364 Compare May 16, 2019 19:08
@ra1028 ra1028 force-pushed the custom-cell-class branch 2 times, most recently from 7d2c2e3 to 85cc265 Compare May 20, 2019 16:03
@ra1028 ra1028 force-pushed the custom-cell-class branch 2 times, most recently from 84f6974 to fef5d92 Compare July 28, 2019 19:46
@ra1028 ra1028 marked this pull request as ready for review July 28, 2019 19:47
@ra1028 ra1028 changed the title [Draft] Custom cell class Custom cell class Jul 28, 2019
@ra1028 ra1028 merged commit c3ead29 into master Jul 29, 2019
@ra1028 ra1028 deleted the custom-cell-class branch July 29, 2019 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants