-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCellEventCoordinator.swift
52 lines (41 loc) · 1.6 KB
/
CellEventCoordinator.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// 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
/// Conforming objects are responsible for handling various cell events.
@MainActor
public protocol CellEventCoordinator: AnyObject {
/// Called when a cell is selected.
/// - Parameter viewModel: The cell view model that corresponds to the cell.
func didSelectCell(viewModel: any CellViewModel)
/// Called when a cell is deselected.
/// - Parameter viewModel: The cell view model that corresponds to the cell.
func didDeselectCell(viewModel: any CellViewModel)
/// Returns the underlying view controller that owns the collection view for the cell.
///
/// You may use this to optionally handle navigation within your cell view model.
var underlyingViewController: UIViewController? { get }
}
extension CellEventCoordinator {
/// Default implementation. Does nothing.
public func didSelectCell(viewModel: any CellViewModel) { }
/// Default implementation. Does nothing.
public func didDeselectCell(viewModel: any CellViewModel) { }
/// Default implementation. Returns `nil`.
public var underlyingViewController: UIViewController? { nil }
}
extension CellEventCoordinator where Self: UIViewController {
/// Default implementation if the conformer is a `UIViewController`.
/// Returns `self`.
public var underlyingViewController: UIViewController? { self }
}