Skip to content

Commit

Permalink
deselect cells
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed May 20, 2024
1 parent b7501cf commit bde9e01
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 0 additions & 1 deletion Example/Sources/List/ListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ final class ListViewController: ExampleViewController, CellEventCoordinator {

// In this example, the cell view models handle cell selection and navigation themselves.


// MARK: View lifecycle

override func viewDidLoad() {
Expand Down
5 changes: 5 additions & 0 deletions Example/Sources/Main/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class ExampleViewController: UIViewController {
self.addReloadButton()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.collectionView.deselectAllItems()
}

// MARK: Actions

@objc
Expand Down
4 changes: 4 additions & 0 deletions ReactiveCollectionsKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
0B01476F2BBCF0330041D432 /* Collection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B01476E2BBCF0330041D432 /* Collection+Extensions.swift */; };
0B25D73A2BFAD31C00EB3664 /* UICollectionView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B25D7392BFAD31C00EB3664 /* UICollectionView+Extensions.swift */; };
0B31B9312BCC5B66006F2078 /* CellEventCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B31B9302BCC5B66006F2078 /* CellEventCoordinator.swift */; };
0B8C6CEC267ED08E0042DFE2 /* SupplementaryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B8C6CEB267ED08E0042DFE2 /* SupplementaryViewModel.swift */; };
0BC1EC28267FC37200FF774F /* SupplementaryHeaderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BC1EC27267FC37200FF774F /* SupplementaryHeaderViewModel.swift */; };
Expand Down Expand Up @@ -50,6 +51,7 @@

/* Begin PBXFileReference section */
0B01476E2BBCF0330041D432 /* Collection+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+Extensions.swift"; sourceTree = "<group>"; };
0B25D7392BFAD31C00EB3664 /* UICollectionView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Extensions.swift"; sourceTree = "<group>"; };
0B31B9302BCC5B66006F2078 /* CellEventCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellEventCoordinator.swift; sourceTree = "<group>"; };
0B8C6CEB267ED08E0042DFE2 /* SupplementaryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupplementaryViewModel.swift; sourceTree = "<group>"; };
0BC1EC27267FC37200FF774F /* SupplementaryHeaderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupplementaryHeaderViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,6 +164,7 @@
0BC1EC29267FC3A000FF774F /* SupplementaryFooterViewModel.swift */,
0BC1EC27267FC37200FF774F /* SupplementaryHeaderViewModel.swift */,
0B8C6CEB267ED08E0042DFE2 /* SupplementaryViewModel.swift */,
0B25D7392BFAD31C00EB3664 /* UICollectionView+Extensions.swift */,
0BC1EC2D267FF46E00FF774F /* ViewRegistration.swift */,
0BFA774F2BB92E36009B9C5B /* ViewRegistrationMethod.swift */,
0BC1EC2B267FE71900FF774F /* ViewRegistrationProvider.swift */,
Expand Down Expand Up @@ -332,6 +335,7 @@
0BC1EC2C267FE71900FF774F /* ViewRegistrationProvider.swift in Sources */,
88FA49082363A7890061F8B2 /* CollectionViewModel.swift in Sources */,
0BFA774E2BB92DC8009B9C5B /* ViewRegistrationViewType.swift in Sources */,
0B25D73A2BFAD31C00EB3664 /* UICollectionView+Extensions.swift in Sources */,
0B01476F2BBCF0330041D432 /* Collection+Extensions.swift in Sources */,
88FA490A2363A7890061F8B2 /* CellViewModel.swift in Sources */,
0BC1EC28267FC37200FF774F /* SupplementaryHeaderViewModel.swift in Sources */,
Expand Down
6 changes: 4 additions & 2 deletions Sources/CollectionViewDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public final class CollectionViewDriver: NSObject {
private func _cellProvider(
collectionView: UICollectionView,
indexPath: IndexPath,
identifier: UniqueIdentifier) -> UICollectionViewCell {
identifier: UniqueIdentifier
) -> UICollectionViewCell {
let cell = self.viewModel.cellViewModel(for: identifier)
precondition(cell != nil, "Inconsistent state. Cell with identifier \(identifier) does not exist.")
return cell!.dequeueAndConfigureCellFor(collectionView: collectionView, at: indexPath)
Expand All @@ -172,7 +173,8 @@ public final class CollectionViewDriver: NSObject {
private func _supplementaryViewProvider(
collectionView: UICollectionView,
elementKind: String,
indexPath: IndexPath) -> UICollectionReusableView? {
indexPath: IndexPath
) -> UICollectionReusableView? {
let supplementaryView = self.viewModel.supplementaryViewModel(ofKind: elementKind, at: indexPath)
return supplementaryView?.dequeueAndConfigureViewFor(collectionView: collectionView, at: indexPath)
}
Expand Down
23 changes: 23 additions & 0 deletions Sources/UICollectionView+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Created by Jesse Squires
// https://www.jessesquires.com
//
// Documentation
// https://jessesquires.github.io/ReactiveCollectionsKit
//
// GitHub
// https://github.com/jessesquires/ReactiveCollectionsKit
//
// Copyright © 2019-present Jesse Squires
//

import Foundation
import UIKit

extension UICollectionView {
public func deselectAllItems(animated: Bool = true) {
self.indexPathsForSelectedItems?.forEach {
self.deselectItem(at: $0, animated: animated)
}
}
}

0 comments on commit bde9e01

Please sign in to comment.