Skip to content

Commit

Permalink
refine: 解决类似RDVTabBarControlle也没有继承UITabbarController,导航栈也不同,那么就需要自己实…
Browse files Browse the repository at this point in the history
…现各种跳转逻辑
  • Loading branch information
summerHearts committed Apr 17, 2024
1 parent a64059d commit 3fcf2bf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Example/TheRouter/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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生成的组件也进行遍历动态注册
Expand Down
2 changes: 1 addition & 1 deletion TheRouter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions TheRouter/Classes/TheRouter+Convenience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions TheRouter/Classes/TheRouter+Jump.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extension TheRouter {
} else {
resultJumpType = .push
}


if let jumpVC = resultVC {
jump(jumpType: resultJumpType, vc: jumpVC)
Expand All @@ -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)
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions TheRouter/Classes/TheRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]()

Expand All @@ -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,
Expand Down Expand Up @@ -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 }
}
Expand Down

0 comments on commit 3fcf2bf

Please sign in to comment.