Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ExpandableCollectionsCollectionViewHandler data source crash #1049

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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