34 lines
1.0 KiB
Swift
34 lines
1.0 KiB
Swift
//
|
|
// CollectionViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 11/29/22.
|
|
// Copyright © 2022 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
protocol CollectionViewController: UIViewController {
|
|
var collectionView: UICollectionView! { get }
|
|
}
|
|
|
|
extension CollectionViewController {
|
|
func clearSelectionOnAppear(animated: Bool) {
|
|
guard let indexPath = collectionView.indexPathsForSelectedItems?.first else {
|
|
return
|
|
}
|
|
if let transitionCoordinator {
|
|
transitionCoordinator.animate { context in
|
|
self.collectionView.deselectItem(at: indexPath, animated: true)
|
|
} completion: { context in
|
|
if context.isCancelled {
|
|
self.collectionView.selectItem(at: indexPath, animated: false, scrollPosition: [] /* UICollectionViewScrollPositionNone */)
|
|
}
|
|
}
|
|
|
|
} else {
|
|
collectionView.deselectItem(at: indexPath, animated: animated)
|
|
}
|
|
}
|
|
}
|