Last active
February 20, 2021 21:39
-
-
Save stevencurtis/758feb2c68cb7f8387c9597dba2ad850 to your computer and use it in GitHub Desktop.
trailingSwipeActionsConfigurationProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func createLayout() -> UICollectionViewLayout { | |
var config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) | |
config.trailingSwipeActionsConfigurationProvider = { indexPath in | |
guard let item = self.dataSource.itemIdentifier(for: indexPath) else {return nil} | |
return UISwipeActionsConfiguration( | |
actions: [UIContextualAction( | |
style: .destructive, | |
title: "Delete", | |
handler: { [weak self] _, _, completion in | |
guard let self = self else {return} | |
self.snapshot.deleteItems([item]) | |
self.dataSource.apply(self.snapshot, animatingDifferences: false) | |
completion(true) | |
} | |
)] | |
) | |
} | |
return UICollectionViewCompositionalLayout.list(using: config) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment