diff --git a/Example/TheRouter/AppDelegate.swift b/Example/TheRouter/AppDelegate.swift index f004aa4..1a3eb19 100644 --- a/Example/TheRouter/AppDelegate.swift +++ b/Example/TheRouter/AppDelegate.swift @@ -27,6 +27,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { NSLog("TheRouter: logMsg- \(url) \(logType.rawValue) \(errorMsg)") } + // 类似RDVTabBarControlle也没有继承UITabbarController,导航栈也不同,那么就需要自己实现各种跳转逻辑 +// TheRouter.customJumpAction { jumpType, instance in +// +// } + // 路由懒加载注册, // - excludeCocoapods: 是否对Cocoapods生成的组件进行动态注册 // - excludeCocoapods = true 不对Cocoapods生成的组件进行动态注册, false 对Cocoapods生成的组件也进行遍历动态注册 diff --git a/TheRouter.podspec b/TheRouter.podspec index 6baccea..345be95 100644 --- a/TheRouter.podspec +++ b/TheRouter.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'TheRouter' - s.version = '1.1.6' + s.version = '1.1.7' s.summary = 'TheRouter一个用于模块间解耦和通信,基于Swift协议进行动态懒加载注册路由与打开路由的工具。同时支持通过Service-Protocol寻找对应的模块,并用 protocol进行依赖注入和模块通信。' # This description is used to generate tags and improve search results. diff --git a/TheRouter/Classes/TheRouter+Convenience.swift b/TheRouter/Classes/TheRouter+Convenience.swift index 179f5fb..0887eab 100644 --- a/TheRouter/Classes/TheRouter+Convenience.swift +++ b/TheRouter/Classes/TheRouter+Convenience.swift @@ -79,6 +79,11 @@ public extension TheRouter { shareInstance.logcat(handle) } + /// addRouterItemLogHandle + class func customJumpAction(_ handle: @escaping CustomJumpActionClouse) { + shareInstance.customJumpAction(handle) + } + /// removeRouter by register urlstring /// /// - Parameter patternString: register urlstring diff --git a/TheRouter/Classes/TheRouter+Jump.swift b/TheRouter/Classes/TheRouter+Jump.swift index 68ac51f..2ac1f32 100644 --- a/TheRouter/Classes/TheRouter+Jump.swift +++ b/TheRouter/Classes/TheRouter+Jump.swift @@ -77,6 +77,7 @@ extension TheRouter { } else { resultJumpType = .push } + if let jumpVC = resultVC { jump(jumpType: resultJumpType, vc: jumpVC) @@ -93,17 +94,21 @@ extension TheRouter { public class func jump(jumpType: LAJumpType, vc: UIViewController) { DispatchQueue.main.async { - switch jumpType { - case .modal: - modal(vc) - case .push: - push(vc) - case .popToTaget: - popToTargetVC(vcClass: type(of: vc)) - case .windowNavRoot: - pusbWindowNavRoot(vc) - case .modalDismissBeforePush: - modalDismissBeforePush(vc) + if let action = shareInstance.customJumpAction { + action(jumpType, vc) + } else { + switch jumpType { + case .modal: + modal(vc) + case .push: + push(vc) + case .popToTaget: + popToTargetVC(vcClass: type(of: vc)) + case .windowNavRoot: + pusbWindowNavRoot(vc) + case .modalDismissBeforePush: + modalDismissBeforePush(vc) + } } } } diff --git a/TheRouter/Classes/TheRouter.swift b/TheRouter/Classes/TheRouter.swift index f97b521..aabfc98 100644 --- a/TheRouter/Classes/TheRouter.swift +++ b/TheRouter/Classes/TheRouter.swift @@ -16,6 +16,9 @@ public class TheRouter: TheRouterParser { public typealias LazyRegisterHandleBlock = (_ url: String, _ userInfo: [String: Any]) -> Any? public typealias RouterLogHandleBlock = (_ url: String, _ logType: TheRouterLogType, _ errorMsg: String) -> Void + // MARK: - 自定义跳转 + public typealias CustomJumpActionClouse = (LAJumpType, UIViewController) -> Void + // MARK: - Private property private var interceptors = [TheRouterInterceptor]() @@ -41,6 +44,8 @@ public class TheRouter: TheRouterParser { public var logcat: RouterLogHandleBlock? + public var customJumpAction: CustomJumpActionClouse? + // MARK: - Public method func addRouterItem(_ patternString: String, priority: uint = 0, @@ -71,6 +76,10 @@ public class TheRouter: TheRouterParser { logcat = handle } + func customJumpAction(_ handle: @escaping CustomJumpActionClouse) { + customJumpAction = handle + } + func removeRouter(_ patternString: String) { patterns = patterns.filter { $0.patternString != patternString } }