@@ -12,13 +12,15 @@ import SafariServices
12
12
let loginRoute : RouteElementIdentifier = " Login "
13
13
let oAuthRoute : RouteElementIdentifier = " OAuth "
14
14
let mainViewRoute : RouteElementIdentifier = " Main "
15
+ let bookmarkRoute : RouteElementIdentifier = " BookMark "
15
16
let repositoryDetailRoute : RouteElementIdentifier = " RepositoryDetail "
16
17
17
18
let storyboard = UIStoryboard ( name: " Main " , bundle: nil )
18
19
19
20
let loginViewControllerIdentifier = " LoginViewController "
20
21
let mainViewControllerIdentifier = " MainViewController "
21
22
let repositoryDetailControllerIdentifier = " RepositoryDetailViewController "
23
+ let bookmarkControllerIdentifier = " BookmarkViewController "
22
24
23
25
class RootRoutable : Routable {
24
26
@@ -113,14 +115,46 @@ class MainViewRoutable: Routable {
113
115
func pushRouteSegment(
114
116
routeElementIdentifier: RouteElementIdentifier ,
115
117
completionHandler: RoutingCompletionHandler ) -> Routable {
116
- let detailViewController = storyboard. instantiateViewControllerWithIdentifier ( repositoryDetailControllerIdentifier)
117
- ( self . viewController as! UINavigationController ) . pushViewController (
118
- detailViewController,
119
- animated: true ,
120
- completion: completionHandler
121
- )
122
-
123
- return RepositoryDetailRoutable ( )
118
+ if routeElementIdentifier == repositoryDetailRoute {
119
+ let detailViewController = storyboard. instantiateViewControllerWithIdentifier ( repositoryDetailControllerIdentifier)
120
+ ( self . viewController as! UINavigationController ) . pushViewController (
121
+ detailViewController,
122
+ animated: true ,
123
+ completion: completionHandler
124
+ )
125
+
126
+ return RepositoryDetailRoutable ( )
127
+
128
+ } else if routeElementIdentifier == bookmarkRoute {
129
+ let bookmarkViewController = storyboard. instantiateViewControllerWithIdentifier ( bookmarkControllerIdentifier)
130
+ ( self . viewController as! UINavigationController ) . pushViewController (
131
+ bookmarkViewController,
132
+ animated: true ,
133
+ completion: completionHandler
134
+ )
135
+
136
+ return BookmarkRoutable ( )
137
+ }
138
+
139
+ fatalError ( " Cannot handle this route change! " )
140
+ }
141
+
142
+ func changeRouteSegment( from: RouteElementIdentifier , to: RouteElementIdentifier , completionHandler: RoutingCompletionHandler ) -> Routable {
143
+
144
+ if from == bookmarkRoute && to == repositoryDetailRoute {
145
+ ( self . viewController as! UINavigationController ) . popViewController ( true ) {
146
+ let repositoryDetailViewController = storyboard. instantiateViewControllerWithIdentifier ( repositoryDetailControllerIdentifier)
147
+ ( self . viewController as! UINavigationController ) . pushViewController (
148
+ repositoryDetailViewController,
149
+ animated: true ,
150
+ completion: completionHandler
151
+ )
152
+ }
153
+
154
+ return BookmarkRoutable ( )
155
+ }
156
+
157
+ fatalError ( " Cannot handle this route change! " )
124
158
}
125
159
126
160
func popRouteSegment(
@@ -131,10 +165,8 @@ class MainViewRoutable: Routable {
131
165
}
132
166
}
133
167
134
- class RepositoryDetailRoutable : Routable {
135
-
136
- }
137
-
168
+ class RepositoryDetailRoutable : Routable { }
169
+ class BookmarkRoutable : Routable { }
138
170
class OAuthRoutable : Routable { }
139
171
140
172
extension UINavigationController {
@@ -147,6 +179,14 @@ extension UINavigationController {
147
179
pushViewController ( viewController, animated: animated)
148
180
CATransaction . commit ( )
149
181
}
182
+
183
+ func popViewController( animated: Bool , completion: Void -> Void ) {
184
+
185
+ CATransaction . begin ( )
186
+ CATransaction . setCompletionBlock ( completion)
187
+ popViewControllerAnimated ( animated)
188
+ CATransaction . commit ( )
189
+ }
150
190
151
191
}
152
192
0 commit comments