GoodCoordinator-iOS
所属分类:iPhone/iOS
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2023-08-22 14:20:15
上 传 者:
sh-1993
说明: SwiftUI中的简化编程导航,
(Simplified programmatic navigation in SwiftUI,)
文件列表:
.swiftpm/ (0, 2023-08-25)
.swiftpm/xcode/ (0, 2023-08-25)
.swiftpm/xcode/package.xcworkspace/ (0, 2023-08-25)
.swiftpm/xcode/package.xcworkspace/xcshareddata/ (0, 2023-08-25)
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (238, 2023-08-25)
Package.swift (1155, 2023-08-25)
Sources/ (0, 2023-08-25)
Sources/Coordinator/ (0, 2023-08-25)
Sources/Coordinator/Coordinator.swift (5161, 2023-08-25)
Sources/Coordinator/Navigation/ (0, 2023-08-25)
Sources/Coordinator/Navigation/NavigationCoordinator.swift (3313, 2023-08-25)
Sources/Coordinator/Navigation/NavigationCoordinatorHelper.swift (1951, 2023-08-25)
Sources/Coordinator/Navigation/NavigationCoordinatorViewWrapper.swift (2257, 2023-08-25)
Sources/Coordinator/Navigation/State/ (0, 2023-08-25)
Sources/Coordinator/Navigation/State/NavigationStack.swift (2211, 2023-08-25)
Sources/Coordinator/Navigation/State/NavigationStackItem.swift (252, 2023-08-25)
Sources/Coordinator/Presentation/ (0, 2023-08-25)
Sources/Coordinator/Presentation/PresentationCoordinator.swift (1964, 2023-08-25)
Sources/Coordinator/Presentation/PresentationCoordinatorHelper.swift (1154, 2023-08-25)
Sources/Coordinator/Presentation/PresentationCoordinatorViewWrapper.swift (1845, 2023-08-25)
Sources/Coordinator/Presentation/State/ (0, 2023-08-25)
Sources/Coordinator/Presentation/State/PresentationItem.swift (280, 2023-08-25)
Sources/Coordinator/Presentation/State/PresentationState.swift (1530, 2023-08-25)
Sources/Coordinator/Presentation/State/PresentationStyle.swift (226, 2023-08-25)
Sources/Coordinator/Root/ (0, 2023-08-25)
Sources/Coordinator/Root/RootCoordinator.swift (1284, 2023-08-25)
Sources/Coordinator/Root/SimpleState.swift (327, 2023-08-25)
Sources/Coordinator/RootItem.swift (150, 2023-08-25)
Sources/Coordinator/Tab/ (0, 2023-08-25)
Sources/Coordinator/Tab/TabCoordinator.swift (5069, 2023-08-25)
Sources/Helpers/ (0, 2023-08-25)
Sources/Helpers/Address.swift (307, 2023-08-25)
Sources/Helpers/ArrayExtension.swift (293, 2023-08-25)
Sources/Helpers/ObservableObject.swift (247, 2023-08-25)
Sources/Helpers/Typealiases.swift (1038, 2023-08-25)
Sources/Navigation/ (0, 2023-08-25)
Sources/Navigation/Router.swift (605, 2023-08-25)
Sources/Navigation/Screen.swift (338, 2023-08-25)
... ...
# GoodCoordinator
### Programmatic navigation made simple, 100% SwiftUI
In just 3 lines of code
```swift
@Push(makeHome) var home
func makeHome(model: HomeModel) -> HomeView { HomeView(model: model) }
route(to: \.home, HomeModel(username: username, password: password))
```
## Usage
1.
Implement a SwiftUI App
```swift
@main struct NavigationApp: App {
private let coordinator = AppCoordinator(())
var body: some Scene {
WindowGroup {
coordinator.makeView()
}
}
}
```
This is a standard implementation for a 100% SwiftUI app.
2.
Implement your first coordinator
```swift
import GoodCoordinator
final class AppCoordinator: NavigationCoordinator {
typealias Input = Void
typealias Output = Void
var state: NavigationStack = .init()
@Root(makeRoot) var root
func makeRoot() -> InitialView {
InitialView() /// SwiftUI View!
}
}
```
Don't worry about code you don't understand yet. Feel free to name the `makeRoot`function in any way you prefer. The function returns the view of your choice. However, to get this code to compile, you need to do one more thing:
3.
Modify your SwiftUI View a bit
```swift
import GoodCoordinator
struct InitialView: View, Screen { /// Extend from Screen as well
...
```
4.
Add a navigation step
```swift
@Push(makeNewScreen) var openNewScreen
func makeNewScreen() -> NewScreen {
NewScreen(viewModel: NewScreenViewModel())
}
```
Add a step into your coordinator and specify, how the view will get constructed.
5.
Navigate!
```swift
@EnvironmentObject var router: Router
// SwiftUI view code
Button(action: {
router.coordinator.route(to: \.openNewScreen)
}, label: {
Text("Go to new screen")
})
// More SwiftUI view code
```
Launch the navigation step from your view.
## Installation
You can use Swift Package Manager (SPM) to import this package. Use the following URL:
```
https://github.com/GoodRequest/GoodCoordinator-iOS.git
```
## Advanced examples
TBD
近期下载者:
相关文件:
收藏者: