Skip to content

Commit 3fcf2bf

Browse files
committed
refine: 解决类似RDVTabBarControlle也没有继承UITabbarController,导航栈也不同,那么就需要自己实现各种跳转逻辑
1 parent a64059d commit 3fcf2bf

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

Example/TheRouter/AppDelegate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2727
NSLog("TheRouter: logMsg- \(url) \(logType.rawValue) \(errorMsg)")
2828
}
2929

30+
// 类似RDVTabBarControlle也没有继承UITabbarController,导航栈也不同,那么就需要自己实现各种跳转逻辑
31+
// TheRouter.customJumpAction { jumpType, instance in
32+
//
33+
// }
34+
3035
// 路由懒加载注册,
3136
// - excludeCocoapods: 是否对Cocoapods生成的组件进行动态注册
3237
// - excludeCocoapods = true 不对Cocoapods生成的组件进行动态注册, false 对Cocoapods生成的组件也进行遍历动态注册

TheRouter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'TheRouter'
11-
s.version = '1.1.6'
11+
s.version = '1.1.7'
1212
s.summary = 'TheRouter一个用于模块间解耦和通信,基于Swift协议进行动态懒加载注册路由与打开路由的工具。同时支持通过Service-Protocol寻找对应的模块,并用 protocol进行依赖注入和模块通信。'
1313

1414
# This description is used to generate tags and improve search results.

TheRouter/Classes/TheRouter+Convenience.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public extension TheRouter {
7979
shareInstance.logcat(handle)
8080
}
8181

82+
/// addRouterItemLogHandle
83+
class func customJumpAction(_ handle: @escaping CustomJumpActionClouse) {
84+
shareInstance.customJumpAction(handle)
85+
}
86+
8287
/// removeRouter by register urlstring
8388
///
8489
/// - Parameter patternString: register urlstring

TheRouter/Classes/TheRouter+Jump.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extension TheRouter {
7777
} else {
7878
resultJumpType = .push
7979
}
80+
8081

8182
if let jumpVC = resultVC {
8283
jump(jumpType: resultJumpType, vc: jumpVC)
@@ -93,17 +94,21 @@ extension TheRouter {
9394

9495
public class func jump(jumpType: LAJumpType, vc: UIViewController) {
9596
DispatchQueue.main.async {
96-
switch jumpType {
97-
case .modal:
98-
modal(vc)
99-
case .push:
100-
push(vc)
101-
case .popToTaget:
102-
popToTargetVC(vcClass: type(of: vc))
103-
case .windowNavRoot:
104-
pusbWindowNavRoot(vc)
105-
case .modalDismissBeforePush:
106-
modalDismissBeforePush(vc)
97+
if let action = shareInstance.customJumpAction {
98+
action(jumpType, vc)
99+
} else {
100+
switch jumpType {
101+
case .modal:
102+
modal(vc)
103+
case .push:
104+
push(vc)
105+
case .popToTaget:
106+
popToTargetVC(vcClass: type(of: vc))
107+
case .windowNavRoot:
108+
pusbWindowNavRoot(vc)
109+
case .modalDismissBeforePush:
110+
modalDismissBeforePush(vc)
111+
}
107112
}
108113
}
109114
}

TheRouter/Classes/TheRouter.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public class TheRouter: TheRouterParser {
1616
public typealias LazyRegisterHandleBlock = (_ url: String, _ userInfo: [String: Any]) -> Any?
1717
public typealias RouterLogHandleBlock = (_ url: String, _ logType: TheRouterLogType, _ errorMsg: String) -> Void
1818

19+
// MARK: - 自定义跳转
20+
public typealias CustomJumpActionClouse = (LAJumpType, UIViewController) -> Void
21+
1922
// MARK: - Private property
2023
private var interceptors = [TheRouterInterceptor]()
2124

@@ -41,6 +44,8 @@ public class TheRouter: TheRouterParser {
4144

4245
public var logcat: RouterLogHandleBlock?
4346

47+
public var customJumpAction: CustomJumpActionClouse?
48+
4449
// MARK: - Public method
4550
func addRouterItem(_ patternString: String,
4651
priority: uint = 0,
@@ -71,6 +76,10 @@ public class TheRouter: TheRouterParser {
7176
logcat = handle
7277
}
7378

79+
func customJumpAction(_ handle: @escaping CustomJumpActionClouse) {
80+
customJumpAction = handle
81+
}
82+
7483
func removeRouter(_ patternString: String) {
7584
patterns = patterns.filter { $0.patternString != patternString }
7685
}

0 commit comments

Comments
 (0)