Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions Example/TheRouter/TheRouterApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,134 +13,144 @@ import TheRouter
TheRouterApi 主要作用是做模块间解耦合,多个模块相互调用,抽出统一的Api,进行跨模块调用
*/

public class TheRouterApi: NSObject, CustomRouterInfo {
public class TheRouterApi: CustomRouterInfo {

public static var patternString = "scheme://router/demo"
public static var routerClass = "TheRouter_Example.TheRouterController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterTabApi: NSObject, CustomRouterInfo {
public class TheRouterTabApi: CustomRouterInfo {

public static var patternString = "scheme://router/tabbar"
public static var routerClass = "TheRouterTabBarController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .showTab

public override init() {}

}


public class TheRouterAApi: NSObject, CustomRouterInfo {
public class TheRouterAApi: CustomRouterInfo {

public static var patternString = "scheme://router/demo1"
public static var routerClass = "TheRouter_Example.TheRouterControllerA"
public var params: [String: Any] { return ["dynamic": "value is dynamic"] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterBApi: NSObject, CustomRouterInfo {
public class TheRouterBApi: CustomRouterInfo {

public static var patternString = "scheme://router/demo2"
public static var routerClass = "TheRouterBController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterBaseAApi: NSObject, CustomRouterInfo {
public class TheRouterBaseAApi: CustomRouterInfo {

public static var patternString = "scheme://router/baseA"
public static var routerClass = "TheRouterBaseAViewController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterBaseBApi: NSObject, CustomRouterInfo {
public class TheRouterBaseBApi: CustomRouterInfo {

public static var patternString = "scheme://router/baseB"
public static var routerClass = "TheRouterBaseBViewController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}


public class TheRouterCApi: NSObject, CustomRouterInfo {
public class TheRouterCApi: CustomRouterInfo {

public static var patternString = "scheme://router/demo33"
public static var routerClass = "TheRouter_Example.TheRouterControllerC"
public var params: [String: Any] { return ["desc":"如果直接调用TheRouterCApi进行路由跳转,此时路由地址demo33是错误的,无法进行跳转,触发断言,仅当动态下发修复之后才能跳转,测试可以注释TheRouterManager.addRelocationHandle这行代码"] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterC3Api: NSObject, CustomRouterInfo {
public class TheRouterC3Api: CustomRouterInfo {

public static var patternString = "scheme://router/demo3"
public static var routerClass = "TheRouter_Example.TheRouterControllerC"
public var params: [String: Any] { return ["desc":"如果直接调用TheRouterCApi进行路由跳转,此时路由地址demo33是错误的,无法进行跳转,触发断言,仅当动态下发修复之后才能跳转,测试可以注释TheRouterManager.addRelocationHandle这行代码"] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterDApi: NSObject, CustomRouterInfo {
public class TheRouterDApi: CustomRouterInfo {

public static var patternString = "scheme://router/demo4"
public static var routerClass = "TheRouter_Example.TheRouterControllerD"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterWebApi: NSObject, CustomRouterInfo {
public class TheRouterWebApi: CustomRouterInfo {

public static var patternString = "scheme://webview/home"
public static var routerClass = "TheRouter_Example.TheRouterWebController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterEApi:NSObject, CustomRouterInfo {
public class TheRouterEApi: CustomRouterInfo {

public static var patternString = "scheme://router/demo9"
public static var routerClass = "TheRouter_Example.TheRouterControllerE"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterLAApi:NSObject, CustomRouterInfo {
public class TheRouterLAApi: CustomRouterInfo {

public static var patternString = "scheme://router/class_prex_test"
public static var routerClass = "TheRouter_Example.LARouterPresentController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .modal

public override init() {}

}

public class TheRouterAnyPrifxApi:NSObject, CustomRouterInfo {
public class TheRouterAnyPrifxApi: CustomRouterInfo {

public static var patternString = "scheme://router/anyClass_prex_test"
public static var routerClass = "TheRouter_Example.AnyPrifxClassTestController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push

public override init() {}

}

public class TheRouterMacroRegisterApi: CustomRouterInfo {

public static var patternString = "scheme://router/demo-macro"
public static var routerClass = "TheRouter_Example.TheRouterMacroRegisterController"
public var params: [String: Any] { return [:] }
public var jumpType: LAJumpType = .push


}
4 changes: 2 additions & 2 deletions Example/TheRouter/TheRouterBaseBViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "TheRouterBaseBViewController.h"
#import <TheRouter/TheRouter-Swift.h>

NSString *const TheRouterTabBarSelecIndex = @"tabBarSelecIndex";
NSString *const TheRouterTabBarSelectIndex = @"tabBarSelectIndex";
@implementation TheRouterBaseBViewController

- (void)viewDidLoad {
Expand All @@ -18,7 +18,7 @@ - (void)viewDidLoad {

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[TheRouerBridge openURL:@"scheme://router/tabbar?jumpType=5" userInfo:@{TheRouterTabBarSelecIndex: @1} complateHandler:^(NSDictionary<NSString *,id> * queries, UIViewController * resultVC) {
[TheRouerBridge openURL:@"scheme://router/tabbar?jumpType=5" userInfo:@{TheRouterTabBarSelectIndex: @1} completeHandler:^(NSDictionary<NSString *,id> * queries, UIViewController * resultVC) {

}];
});
Expand Down
136 changes: 136 additions & 0 deletions Example/TheRouter/TheRouterControllerA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,26 @@ class TheRouterControllerA: UIViewController {

self.resultLabel.text = self.desc

let button = UIButton(type: .custom)
button.setTitle("去ControllerA", for: .normal)
button.setTitleColor(.black, for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 200, height: 44)
button.center = CGPoint(x: view.center.x, y: view.center.y + 200)
button.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
view.addSubview(button)

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {

guard let _resultCallBack = self.qrResultCallBack?.closure else { return }
_resultCallBack(["扫码回调了":"1"])
}
// Do any additional setup after loading the view, typically from a nib.
}

@objc
func buttonAction(_ button: UIButton) {
TheRouter.openURL("scheme://router/A")
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
Expand All @@ -63,3 +76,126 @@ extension TheRouterControllerA: TheRouterable {
["scheme://router/demo1"]
}
}

// MARK: - 用于验证A->B->C-D,删除ABC三个栈的功能

class ControllerA: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "A"

view.backgroundColor = .red

let button = UIButton(type: .custom)
button.setTitle("去ControllerB", for: .normal)
button.setTitleColor(.black, for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 200, height: 44)
button.center = view.center
button.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
view.addSubview(button)
}

@objc
func buttonAction(_ button: UIButton) {
TheRouter.openURL("scheme://router/B")
}
}

extension ControllerA: TheRouterable {

static var patternString: [String] {
["scheme://router/A"]
}

}

class ControllerB: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "B"

view.backgroundColor = .green

let button = UIButton(type: .custom)
button.setTitle("去ControllerC", for: .normal)
button.setTitleColor(.black, for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 200, height: 44)
button.center = view.center
button.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
view.addSubview(button)
}

@objc
func buttonAction(_ button: UIButton) {
TheRouter.openURL("scheme://router/C")
}
}

extension ControllerB: TheRouterable {

static var patternString: [String] {
["scheme://router/B"]
}

}

class ControllerC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "C"

view.backgroundColor = .orange

let button = UIButton(type: .custom)
button.setTitle("去ControllerD", for: .normal)
button.setTitleColor(.black, for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 200, height: 44)
button.center = view.center
button.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
view.addSubview(button)
}

@objc
func buttonAction(_ button: UIButton) {
TheRouter.openURL("scheme://router/D", userInfo: [LARemovePatterns: ["scheme://router/B", "scheme://router/C"]])
}
}

extension ControllerC: TheRouterable {

static var patternString: [String] {
["scheme://router/C"]
}

}

class ControllerD: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "D"

view.backgroundColor = .randomColor

let button = UIButton(type: .custom)
button.setTitle("返回TheRouterControllerA", for: .normal)
button.setTitleColor(.black, for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 200, height: 44)
button.center = view.center
button.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
view.addSubview(button)
}

@objc
func buttonAction(_ button: UIButton) {
TheRouter.openURL("scheme://router/demo1", userInfo: [LAJumpTypeKey: "2"])
}
}

extension ControllerD: TheRouterable {

static var patternString: [String] {
["scheme://router/D"]
}

}

Loading