Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.88k stars 1.54k forks source link

Swipe IGListKit collection cell #620

Closed jorgelp94 closed 7 years ago

jorgelp94 commented 7 years ago

Is there a way to swipe to delete a cell just like in a UITableView?

jessesquires commented 7 years ago

Thanks @jorgelp94 !

We don't provide this and it's out-of-scope for what IGListKit provides. This functionality would be better in its own library.

manonthemoon42 commented 7 years ago

I'm not sure if that feature is really out of scope. I'm sure that it's a feature that any users would love to have. IGListKit allow to create a List. It could have that nice feature for deletions.

Actually, I saw that Instagram comment's list has this feature. When we swipe a particular comment, we get the options to :

I'm wondering if Comments View Controller is also using IGListKit. I would tend to think that this screen might use a UITableView instead. Since table view has this feature for free. If it's the case, it would be a big plus for IGListKit to have this generic feature.

@jessesquires , @rnystrom , thoughts?

jorgelp94 commented 7 years ago

@manonthemoon42 yeah I saw that too, that's why I thought IGListKit already had a swipe feature.

rnystrom commented 7 years ago

@manonthemoon42 @jorgelp94 yup all IGListKit. Comment used to be UITableView but even then we wrote our own swipe-actions b/c we wanted a "swipe all the way to delete" gesture as well.

I would absolutely love if someone wrote a section controller or UICollectionViewCell with this built-in. We'd be happy to link to it and recommend its usage. Not sure if we can commit to baking it into IGListKit at this moment though (cc @jessesquires for more thoughts there).

You might also want to follow along and help out w/ #584, that will make this a lot easier!

staticdreams commented 7 years ago

For anyone still looking to implement this I found that SwipeCellKit works great with IGListKit. Specifically this fork that replaces tableView with collectionView. It is also very easy to implement: just import SwipeCellKit into your SectionController and instruct it to be your collectionViewCell's delegate. Implement 2 required delegate methods (refer to readme) and that's it! Here's how my implementation looks like :)

may-28-2017 14-41-53

magonicolas commented 7 years ago

@staticdreams Im trying to achieve what you did. If I understood correctly, apart of what you explicitly say, My Cell should have a property called delegate with should be of type SwipeTableViewCellDelegate.All the other steps you mention have been done, and I still can´t make it work. Its weird that the method are like Table View since it is a collection view. I did install the fork you direct us, but Not working for me :( Can you please explain more the implementation or maybe send an example project?

magonicolas commented 7 years ago

Please add a Swipe action like table views.

gbtagliari commented 7 years ago

@magonicolas you should subclass SwipeTableViewCell from https://github.com/mschonvogel/SwipeCellKit (important: branch "develop"!) and set delegate from cell!

bofiaza commented 7 years ago

I think https://github.com/mschonvogel/SwipeCellKit only works when the IGListSectionController only returns one type of UICollectionViewCell; It won't totally work if it returns multiple types and UICollectionView has custom layout.

denmore commented 6 years ago

This is a very useful thread - especially the @staticdreams pointing to the branch that supports UICollectionView. In my case, I am trying to get the entire IGListKit ListSection swipeable. Does anyone have experience with or advice on this?

jbouaziz commented 6 years ago

I personally think that IGListKit is great because it allows you split what should be a complicated cell layout into multiple reusable components.

@denmore if you need to swipe an entire section and therefore multiple cells, it'd have to be pretty big and complicated. That being said and assuming (I might be wrong) that yours is, maybe consider using a long press gesture instead? Again, I don't know your layout so I could be wrong.

If you're still going that route, you'd have to write your own fork of SwipeCellKit in order to allow multiple cells to be swiped at the same time. And then probably sync the pan gesture at the section controller level.

Smiller193 commented 6 years ago

@staticdreams an example would be nice

sjang42 commented 4 years ago

Any update?

shadowsheep1 commented 4 years ago

@sjang42 nope, but as mentioned above you can use https://github.com/SwipeCellKit/SwipeCellKit that works well.

Ricardo1980 commented 3 years ago

@sjang42 nope, but as mentioned above you can use https://github.com/SwipeCellKit/SwipeCellKit that works well.

Quick question, do I need a special branch or tweaking? Thanks a lot.

panjiulong commented 3 years ago

SwipeCellKit and iGListKit have no way to achieve sliding deletion. I use a collectioncell inherited from SwipeCollectionViewCell, and return this cell in the sectionController to implement the proxy sliding finger sliding cell. The proxy method is called, but the delete button is not displayed.

class CollectCell: SwipeCollectionViewCell {}

class CollectionSectionController:ListSectionController{
    var navigator: Navigator = Navigator()
    override init() {
        super.init()
        displayDelegate = self
        minimumLineSpacing = 10
        minimumInteritemSpacing = 10
        supplementaryViewSource = self

    }
    var model: CollectModel?

    override func sizeForItem(at index: Int) -> CGSize {
        return CGSize(width: collectionContext!.containerSize.width, height: 116)
    }

    override func cellForItem(at index: Int) -> UICollectionViewCell {
        let cell = collectionContext!.dequeueReusableCell(of: CollectCell.self, for: self, at: index) as! CollectCell
        cell.model = model
        cell.delegate = self
        return cell
    }
    override func canMoveItem(at index: Int) -> Bool {
        return true
    }
    override func didSelectItem(at index: Int) {
        print("didSelectItem \(index)")
        guard let model = model,model.isSale else { return }
        SensorsSellBury.shared.sellSourceType = .userCenter

        (viewController as? BaseViewController)?.navigator.push(URLConfig.getGoodsDetailURL(goodsId: model.id, mClass: EnterGoodsDetailType.other.mClass, lastPageType: .collection(productId: "\(model.id)")))
    }
    override func didUpdate(to object: Any) {
        model = object as? CollectModel
    }
}
extension CollectionSectionController:SwipeCollectionViewCellDelegate{
    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
            print(indexPath)
        }
        let aaAction = SwipeAction(style: .default, title: "Delete") { action, indexPath in
            print(indexPath)
        }
        let bbAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
            print(indexPath)
        }

        deleteAction.image = R.image.shopping_delete()

        return [deleteAction,aaAction,bbAction]
    }
}
AdamBCo commented 1 year ago

When setting the expansionStyle to .destructive for SwipeCellKit, I get the following error:

Performing reloadData as a fallback — Invalid update: invalid number of items in section 2. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out). Collection view: <UICollectionView: 0x158849600; frame = (0 0; 393 567.333); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x281ad83f0>; backgroundColor = <UIDynamicCatalogColor: 0x2837520d0; name = systemSurface>; layer = <CALayer: 0x2814b0aa0>; contentOffset: {0, 0}; contentSize: {393, 2364}; adjustedContentInset: {0, 0, 0, 0}; layout: <UICollectionViewFlowLayout: 0x155fd3d50>; dataSource: <IGListAdapter: 0x282f323c0>>

Has @anyone else run into this problem? Any solutions or points of advice using IGListKit & SwipeCellKit at the same time.