Skip to content

Commit

Permalink
Add two new protocol methods that can support custom NavigationContro…
Browse files Browse the repository at this point in the history
…ller #3
  • Loading branch information
chaichai666 committed Feb 12, 2019
1 parent 3810820 commit 59f3ec0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Navi/Navi/NaviManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ extension NaviManager {

extension NaviManager {
func previousController() -> UIViewController? {
if let previousVC = navigator.previousController?() {
return previousVC
}
let count = topViewController()?.navigationController?.viewControllers.count ?? 0
if count > 1 {
return topViewController()?.navigationController?.viewControllers[count - 2]
Expand All @@ -252,6 +255,9 @@ extension NaviManager {
}

func topViewController() -> UIViewController? {
if let topVC = navigator.currentController?() {
return topVC
}
guard let rootViewController = UIApplication.shared.keyWindow?.rootViewController else {
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions Navi/Navi/NaviProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public protocol NaviProtocol: class {
func tabBarViewControllers() -> [String]
func rootNodeName() -> String
func mapBusinessLogicDocument() -> [String: String]
@objc optional func currentController() -> UIViewController
@objc optional func previousController() -> UIViewController
}
Binary file not shown.
10 changes: 5 additions & 5 deletions NaviDemo/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class Navigation: NaviProtocol {
}

func mapBusinessLogicDocument() -> [String: String] {
return ["NaviDemo.FavoriteViewController": "https://www.farfetch.com",
"NaviDemo.ListViewController": "https://www.farfetch.com",
"NaviDemo.DetailViewController": "https://www.farfetch.com",
"NaviDemo.SettingViewController": "https://www.farfetch.com",
"NaviDemo.DownloadViewController": "https://www.farfetch.com"]
return ["NaviDemo.FavoriteViewController": "https://en.wikipedia.org/wiki/Marie_Curie",
"NaviDemo.ListViewController": "https://en.wikipedia.org/wiki/Albert_Einstein",
"NaviDemo.DetailViewController": "https://en.wikipedia.org/wiki/Tu_Youyou",
"NaviDemo.SettingViewController": "https://en.wikipedia.org/wiki/Alan_Turing",
"NaviDemo.DownloadViewController": "https://en.wikipedia.org/wiki/Main_Page"]
}
}

0 comments on commit 59f3ec0

Please sign in to comment.