主要特性 • 如何使用 • 贡献者 • 许可证 • 更新日志
要使用这个包,您可以简单地使用 Swift Package Manager 安装,并按照以下步骤操作
import SwiftUI
enum AppRoute: Routable {
case login
case home
case profile(userID: String)
case settings
case detail(itemID: Int)
// The builder property returns the corresponding view for each route.
var view: any View {
switch self {
case .login: LoginView()
case .home: HomeView()
case .profile(let userID): ProfileView(userID: userID)
case .settings: SettingsView()
case .detail(let itemID): DetailView(itemID: itemID)
}
}
}
import SwiftUI
struct ContentView: View {
var body: some View {
// The RouterView is initialized with the root view of the app.
RouterView<AppRoute>(rootView: .home)
}
}
import SwiftUI
// Import the RouterKit to use in your project
import RouterKit
struct HomeView: View {
// Every view that was rendered by RouterView has a router inside
@EnvironmentObject var router: Router<AppRoute>
var body: some View {
VStack {
Button("Push view") {
router.push(to: .profile(userID: '<user-id>'))
}
Button("Push view without animation") {
router.push(to: .profile(userID: '<user-id>'), animate: false)
}
Button("Pop view") {
router.pop()
}
Button("Pop to root view") {
router.popToRoot()
}
Button("Replace root view to another") {
router.replaceRootView(to: .settings)
}
}
}
}
这个项目是一个 邮件软件。这意味着,如果您喜欢使用这个应用程序,或者它在任何方面对您有所帮助,我希望您发送一封电子邮件到 berkspar@gmail.com,告诉我您对这个软件的任何想法。我将非常感激!
这个包是在 Apple Developer Academy 上创建的。
Apache
berkspar.com · GitHub @berkspar · LinkedIn in/berkspar ·