-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFluidStackPath.swift
More file actions
75 lines (53 loc) · 1.86 KB
/
Copy pathFluidStackPath.swift
File metadata and controls
75 lines (53 loc) · 1.86 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import UIKit
public struct FluidStackPath: Equatable {
public enum Component: Equatable {
public struct Volatile: Equatable {
public let objectIdentifier: ObjectIdentifier
public private(set) weak var ref: UIViewController?
}
public struct Identifiable: Equatable {
public static func == (lhs: Self, rhs: Self) -> Bool {
guard lhs.id == rhs.id else { return false }
guard lhs.viewControllerType == rhs.viewControllerType else { return false }
return true
}
public let id: AnyHashable
public let viewControllerType: UIViewController.Type
@MainActor
public init(_ viewController: some FluidIdentifiableViewController) {
self.id = viewController.fluidIdentifier as AnyHashable
self.viewControllerType = type(of: viewController)
}
public func restore<Target: FluidIdentifiableViewController>(_ target: Target.Type) -> Target.FluidID? {
guard viewControllerType == target else { return nil }
guard let id = id as? Target.FluidID else { return nil }
return id
}
}
case volatile(Volatile)
case identifiable(AnyFluidIdentifiableViewController)
}
public private(set) var components: [Component] = []
public init() {
}
public init(components: [Component]) {
self.components = components
}
public mutating func append(_ component: Component) {
components.append(component)
}
public mutating func removeLast(_ k: Int = 1) {
components.removeLast(k)
}
}
public struct AnyFluidIdentifiableViewController: Equatable {
public var base: AnyHashable
public init(_ base: some FluidIdentifiableViewController) {
self.base = base as AnyHashable
}
}
@MainActor
public protocol FluidIdentifiableViewController: UIViewController {
associatedtype FluidID: Hashable
var fluidIdentifier: FluidID { get }
}