Add Mark as (Un)read swipe action
This commit is contained in:
parent
f4196a2c26
commit
2380eeee4a
|
@ -60,6 +60,22 @@ class ItemsViewController: UIViewController {
|
||||||
|
|
||||||
var configuration = UICollectionLayoutListConfiguration(appearance: .plain)
|
var configuration = UICollectionLayoutListConfiguration(appearance: .plain)
|
||||||
configuration.backgroundColor = .clear
|
configuration.backgroundColor = .clear
|
||||||
|
configuration.trailingSwipeActionsConfigurationProvider = { [unowned self] indexPath in
|
||||||
|
guard let itemID = self.dataSource.itemIdentifier(for: indexPath) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
let item = fervorController.persistentContainer.viewContext.object(with: itemID) as! Item
|
||||||
|
let action = UIContextualAction(style: .normal, title: item.read ? "Mark as Unread" : "Mark as Read") { _, _, completion in
|
||||||
|
Task {
|
||||||
|
await self.fervorController.markItem(item, read: !item.read)
|
||||||
|
completion(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
action.image = UIImage(systemName: item.read ? "checkmark.circle" : "checkmark.circle.fill")
|
||||||
|
return UISwipeActionsConfiguration(actions: [
|
||||||
|
action
|
||||||
|
])
|
||||||
|
}
|
||||||
let layout = UICollectionViewCompositionalLayout.list(using: configuration)
|
let layout = UICollectionViewCompositionalLayout.list(using: configuration)
|
||||||
collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
|
collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
|
||||||
collectionView.delegate = self
|
collectionView.delegate = self
|
||||||
|
|
Loading…
Reference in New Issue