-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathRoutable.swift
More file actions
115 lines (104 loc) · 5.15 KB
/
Routable.swift
File metadata and controls
115 lines (104 loc) · 5.15 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// Routable.swift
// Meet
//
// Created by Benjamin Encz on 12/3/15.
// Copyright © 2015 DigiTales. All rights reserved.
//
/// Human-readable typealias for the completion handler, which _must_ run in all paths to unblock the internal `semaphore_wait()`
public typealias RoutingCompletionHandler = () -> Void
public protocol Routable {
/// Push a valid route onto the stack.
///
/// Should trigger `fatalError()` if the route being pushed does not exist or otherwise is not supported for any reason.
///
/// _Must_ pass along `completionHandler` or ultimately call it, to unblock the `semaphore_wait()` used internally.
///
/// - Parameters:
/// - routeElementIdentifier: the route identifier to push
/// - animated: whether or not to animate the transition
/// - completionHandler: the callback to run on completion of the navigation event.
/// - Returns: a valid routable to keep on the stack.
func pushRouteSegment(
_ routeElementIdentifier: RouteElementIdentifier,
animated: Bool,
completionHandler: @escaping RoutingCompletionHandler) -> Routable
/// Pop a valid route off the stack.
///
/// Should trigger `fatalError()` if the route being popped does not exist or otherwise is not supported for any reason.
///
/// _Must_ pass along `completionHandler` or ultimately call it, to unblock the `semaphore_wait()` used internally.
///
/// - Parameters:
/// - routeElementIdentifier: the route identifier to pop
/// - animated: whether or not to animate the transition
/// - completionHandler: the callback to run on completion of the navigation event.
func popRouteSegment(
_ routeElementIdentifier: RouteElementIdentifier,
animated: Bool,
completionHandler: @escaping RoutingCompletionHandler)
/// Swap the current route with another, valid route.
///
/// Should trigger `fatalError()` if the route to be added does not exist or otherwise is not supported for any reason.
///
/// _Must_ pass along `completionHandler` or ultimately call it, to unblock the `semaphore_wait()` used internally.
///
/// - Parameters:
/// - routeElementIdentifier: the route identifier to change to
/// - animated: whether or not to animate the transition
/// - completionHandler: the callback to run on completion of the navigation event.
/// - Returns: a valid routable to keep on the stack.
func changeRouteSegment(
_ from: RouteElementIdentifier,
to: RouteElementIdentifier,
animated: Bool,
completionHandler: @escaping RoutingCompletionHandler) -> Routable
}
extension Routable {
/// Predetermined inability to push a route onto the stack.
///
/// All Routable-implementing classes should override this function to avoid runtime errors with `fatalError()`.
///
/// - Parameters:
/// - routeElementIdentifier: the route identifier to push
/// - animated: whether or not to animate the transition
/// - completionHandler: the callback to run on completion of the navigation event.
/// - Returns: a valid routable to keep on the stack.
public func pushRouteSegment(
_ routeElementIdentifier: RouteElementIdentifier,
animated: Bool,
completionHandler: @escaping RoutingCompletionHandler) -> Routable {
fatalError("This routable cannot push segments. You have not implemented it. (Asked \(type(of: self)) to push \(routeElementIdentifier))")
}
/// Predetermined inability to pop the current route off the stack.
///
/// All Routable-implementing classes should override this function to avoid runtime errors with `fatalError()`.
///
/// - Parameters:
/// - routeElementIdentifier: the current route identifier
/// - animated: whether or not to animate the transition
/// - completionHandler: the callback to run on completion of the navigation event.
public func popRouteSegment(
_ routeElementIdentifier: RouteElementIdentifier,
animated: Bool,
completionHandler: @escaping RoutingCompletionHandler) {
fatalError("This routable cannot pop segments. You have not implemented it. (Asked \(type(of: self)) to pop \(routeElementIdentifier))")
}
/// Predetermined inability to swap the current route with another, valid route.
///
/// All Routable-implementing classes should override this function to avoid runtime errors with `fatalError()`.
///
/// - Parameters:
/// - from: the current route identifier
/// - to: the route identifier to change to
/// - animated: whether or not to animate the transition
/// - completionHandler: the callback to run on completion of the navigation event.
/// - Returns: a valid routable to keep on the stack.
public func changeRouteSegment(
_ from: RouteElementIdentifier,
to: RouteElementIdentifier,
animated: Bool,
completionHandler: @escaping RoutingCompletionHandler) -> Routable {
fatalError("This routable cannot change segments. You have not implemented it. (Asked \(type(of: self)) to change from \(from) to \(to))")
}
}