如何引入?
dependencies: [
.package(url: "https://github.com/shaokui-gu/GM.git", .upToNextMajor(from: "0.0.5"))
]
pod 'GM', :git => "https://github.com/shaokui-gu/GM.git", :tag => '0.0.5'
GM 制定了一套简洁的命名路由管理系统来管理界面跳转
class AppPages {
static let pages = [
Router.RoutePage(
name:"/",
page: { params in
return KKMainController()
}
),
Router.RoutePage(
name:"/inBox",
page: { params in
return GMSwiftUIPage(rootView: KKMessageBoxPage())
}
)
]
}
想要使用它你首先需要:
@main
class AppDelegate: GMAppDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
GM.registerPages(AppPages.pages)
GM.setRouterDelegate(KKRouterDelegate())
window = GMWindow(windowScene: windowScene)
window!.setRootPage("/")
window!.makeKeyAndVisible()
/// others...
return true
}
}
class SceneDelegate: GMSceneDelegate {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
GM.registerPages(AppPages.pages)
GM.setRouterDelegate(KKRouterDelegate())
window = GMWindow(windowScene: windowScene)
window?.setRootPage("/")
window!.makeKeyAndVisible()
/// others...
}
}
}
注:GM 会自动为 App 创建一个 UINavigationController 作为 RootViewController, setRootPage 对应页面作为这个 navigation 的 rootViewController
/// push
GM.toNamed("/setting")
GM.offToNamed("/setting")
/// presentModal
GM.toModalNamed("/setting")
/// 返回上一个
GM.back()
/// 返回到根路由
GM.backTo("/")
GM 支持以任意 NSObject 对象作为一个状态进行管理,该对象只需要遵循 StateObjectProtocol 接口协议
public protocol StateObjectProtocol {
var identifire:String { get set }
}
class CustomState : NSObject, StateObjectProtocol {
var identifire = "custom"
var title:String = ""
}
let state = CustomState()
/// 存储
GM.put(state)
/// 获取
let state = GM.find(CustomState.self, identifire: "custom")
state?.title = "找到了"
/// 移除
GM.popState(state)
GM 重写UIViewController 的生命周期,使用 GM后 将无法 override UIViewController 原来的生命周期
protocol GMPageLifeCycle {
func onPageAppear() -> Void
func onPageDisappear() -> Void
func onPageInit() -> Void
func onPageLoaded() -> Void
func onPageDestroy() -> Void
func onPageBoundsUpdated(_ bounds:CGRect) -> Void
}
GM.log('hellow world')
let version = GM.appVersion
let buildVersion = GM.buildVersion
let windowSize = GM.windowSize
let safeArea = GM.safeArea
let deviceID = GM.deviceID
let platform = GM.platform
let osVersion = GM.osVersion
link |
Stars: 3 |
Last commit: Yesterday |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics