Skip to content

Commit

Permalink
Fix ExpandableCollectionsCollectionViewHandler data source crash (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak authored Jan 8, 2025
1 parent dbdf62d commit 757aa35
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

final class ExpandableCollectionsCollectionViewHandler: NSObject {
private let collectionsSection: Int = 0
private unowned let collectionView: UICollectionView
private weak var collectionView: UICollectionView?
private unowned let dbStorage: DbStorage
private unowned let dragDropController: DragDropController
private unowned let viewModel: ViewModel<CollectionsActionHandler>
Expand Down Expand Up @@ -66,6 +66,7 @@ final class ExpandableCollectionsCollectionViewHandler: NSObject {
// MARK: - Scrolling

func selectIfNeeded(collectionId: CollectionIdentifier, tree: CollectionTree, scrollToPosition: Bool) {
guard let collectionView, let dataSource else { return }
let selectedIndexPaths = collectionView.indexPathsForSelectedItems ?? []

if selectedIndexPaths.count > 1 {
Expand All @@ -75,7 +76,6 @@ final class ExpandableCollectionsCollectionViewHandler: NSObject {
}
}

guard let dataSource = dataSource else { return }
let snapshot = dataSource.snapshot(for: collectionsSection)

if !snapshot.items.contains(where: { $0.identifier == collectionId }) {
Expand All @@ -101,7 +101,7 @@ final class ExpandableCollectionsCollectionViewHandler: NSObject {
}

func update(with tree: CollectionTree, selectedId: CollectionIdentifier, animated: Bool, completion: (() -> Void)? = nil) {
guard let dataSource = dataSource else { return }
guard let collectionView, let dataSource else { return }
let newSnapshot = tree.createSnapshot(selectedId: selectedId)

if dataSource.snapshot(for: collectionsSection).items.count == newSnapshot.items.count {
Expand Down

0 comments on commit 757aa35

Please sign in to comment.