Open liubiaocong opened 5 years ago
Like this: enum TestType: String { case test1 = "1" case test2 = "2" }
func TestViewController(taskType: TestType) -> String { return "thor://workflow/unprocessed/review/feedbackpage/(taskType)" }
can it work when I want to get the value of "taskType"?
I structure using enum like this. May it match your requirements
struct DeeplinkManager {
static let sharedInstance = DeeplinkManager()
private var navigator: NavigatorType!
init() {
navigator = Navigator()
NavigationMap.initialize(navigator: navigator)
}
@discardableResult
func handleDeeplink(url: URL, animated: Bool = true, completion: (() -> Void)? = nil) -> UIViewController? {
if !navigator.open(url) {
return navigator.present(url, wrap: UINavigationController.self, animated: animated, completion: completion)
}
return nil
}
}
//Deeplink kind
enum NavigationMap{
case chat, chatInbox
case favourite
}
//Init
extension NavigationMap: CaseIterable {
static func initialize(navigator: NavigatorType) {
for deeplink in NavigationMap.allCases {
navigator.handle(deeplink.pattern(), deeplink.factory(navigator: navigator))
}
}
}
//Pattern
extension NavigationMap {
func pattern() -> String {
switch self {
case .chat:
return "sample://chatLink"
case .chatInbox:
return "sample://chat_inbox"
case .favourite:
return "sample://favourite"
}
}
}
//Handler factory
extension NavigationMap {
func factory(navigator: NavigatorType) -> URLOpenHandlerFactory {
return {url, values, context in
switch self {
case .chat, .chatInbox:
self.openChatVC(navigator:navigator)
case .favourite:
self.openFavourite(navigator: navigator)
}
}
}
}
extension NavigationMap {
private func openFavourite(navigator: NavigatorType) {
if UserProfileManager.sharedInstance.isLogin() {
let favoriteViewController = FavoriteViewController.instantiate()
let navController = NavigationController(rootViewController: favoriteViewController)
navigator.present(navController)
}
}
private func openChatVC(navigator: NavigatorType) {
let chatVC = ChatViewController.instantiate()
let navController = NavigationController(rootViewController: chatVC)
navigator.present(navController)
}
}
}
@liubiaocong may be you can see extension for URLNavigator
Can you provide an example or a description?