Skip to content

TryRuntime/UCRouterSwift

Repository files navigation

UCRouterSwift

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

UCRouterSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'UCRouterSwift'

How to use

参考Example

  • 1.设置导航协议, URL过滤协议在主工程中的代理

      UCRouter.default.setNavgationAndFilter(navgation: NavgationDelegate(), filter: FilterDelegate())
    
  • 2.抽出一个可以共同依赖的协议层,这些协议需要继承UCRoutable, 在register函数中可以对url进行注册,另外如果我们想本地对外界提供一些支持不要通过url的方式,这里可以在各自的协议声明一些函数,参数和返回值都必须是基本类型,防止耦合.可以参考下ModuleAProtocolModuleA两个文件.

这里举一些url注册的例子:

UCRouter.default.registUrl("oral/test") { (routerInfo) -> UIViewController? in
    return VC2()
}
 UCRouter.default.registUrl("oral") { (routerInfo) -> UIViewController? in
    return VC2()
}
 UCRouter.default.registUrl("web") { (routerInfo) -> UIViewController? in
    guard let url = routerInfo.urlQuery?["url"] else {return nil}
    let webView = WKWebView(frame: UIScreen.main.bounds)
    let vc = UIViewController()
    vc.view.addSubview(webView)
    webView.load(URLRequest(url: URL(string: url)!))
    
    return vc
}

调用的例子:

func openWeb(_ sender: Any) {
    UCRouter.default.routeUrlStr("demo://web/?url=https://www.baidu.com", navgationType: .push(animated: true), params: ["abc": "111"])
}
func normalJump(_ sender: Any) {
    UCRouter.default.routeUrlStr("demo://oral/test?haha=111", navgationType: .push(animated: true), params: ["abc": "111"])
}

协议层是可以大家一起去依赖的,他并不会耦合什么东西,真正实现这些协议的其实还是在各自的模块中.

  • 3.由于Swift自注册没有什么好的方案,这里需要手动对实现协议的各个Module进行注册

      UCRouter.default.registProtoclAndModule(UCRouterKey<ModuleAProtocol>(), ModuleA.self)
    

Author

Link913, [email protected]

License

UCRouterSwift is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published