SwiftfulRouting

所属分类:iPhone/iOS
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2023-08-24 02:19:13
上 传 者sh-1993
说明:  SwiftUI应用程序中编程导航的声明性框架。,
(Declarative framework for programmatic navigation in SwiftUI applications.,)

文件列表:
.swiftpm/ (0, 2023-08-30)
.swiftpm/xcode/ (0, 2023-08-30)
.swiftpm/xcode/package.xcworkspace/ (0, 2023-08-30)
.swiftpm/xcode/package.xcworkspace/xcshareddata/ (0, 2023-08-30)
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (238, 2023-08-30)
LICENSE (1079, 2023-08-30)
Package.swift (1122, 2023-08-30)
Sources/ (0, 2023-08-30)
Sources/SwiftfulRouting/ (0, 2023-08-30)
Sources/SwiftfulRouting/Components/ (0, 2023-08-30)
Sources/SwiftfulRouting/Components/NavigationViewIfNeeded.swift (2091, 2023-08-30)
Sources/SwiftfulRouting/Components/VisualEffectViewRepresentable.swift (534, 2023-08-30)
Sources/SwiftfulRouting/Core/ (0, 2023-08-30)
Sources/SwiftfulRouting/Core/AnyRouter.swift (4492, 2023-08-30)
Sources/SwiftfulRouting/Core/Router.swift (1190, 2023-08-30)
Sources/SwiftfulRouting/Core/RouterView.swift (11376, 2023-08-30)
Sources/SwiftfulRouting/Extensions/ (0, 2023-08-30)
Sources/SwiftfulRouting/Extensions/Binding+EXT.swift (2331, 2023-08-30)
Sources/SwiftfulRouting/Extensions/Set+EXT.swift (222, 2023-08-30)
Sources/SwiftfulRouting/Models/ (0, 2023-08-30)
Sources/SwiftfulRouting/Models/AnyAlert.swift (1653, 2023-08-30)
Sources/SwiftfulRouting/Models/AnyDestination.swift (554, 2023-08-30)
Sources/SwiftfulRouting/Options/ (0, 2023-08-30)
Sources/SwiftfulRouting/Options/AlertOption.swift (156, 2023-08-30)
Sources/SwiftfulRouting/Options/ModalConfiguration.swift (818, 2023-08-30)
Sources/SwiftfulRouting/Options/SegueOption.swift (266, 2023-08-30)
Sources/SwiftfulRouting/Options/SheetConfiguration.swift (2777, 2023-08-30)
Sources/SwiftfulRouting/Options/UrlOption.swift (198, 2023-08-30)
Sources/SwiftfulRouting/ViewModifiers/ (0, 2023-08-30)
Sources/SwiftfulRouting/ViewModifiers/AlertViewModifier.swift (896, 2023-08-30)
Sources/SwiftfulRouting/ViewModifiers/ConfirmationDialogViewModifier.swift (1061, 2023-08-30)
Sources/SwiftfulRouting/ViewModifiers/FullScreenCoverViewModifier.swift (618, 2023-08-30)
Sources/SwiftfulRouting/ViewModifiers/ModalViewModifier.swift (2643, 2023-08-30)
Sources/SwiftfulRouting/ViewModifiers/NavigationLinkViewModifier.swift (1467, 2023-08-30)
Sources/SwiftfulRouting/ViewModifiers/SheetViewModifier.swift (2011, 2023-08-30)
Tests/ (0, 2023-08-30)
Tests/SwiftfulRoutingTests/ (0, 2023-08-30)
Tests/SwiftfulRoutingTests/SwiftfulRoutingTests.swift (366, 2023-08-30)
... ...

# SwiftfulRouting A native, declarative framework for programmatic navigation in SwiftUI applications, fully decoupled from the View. **Setup time:** 1 minute **Sample project:** https://github.com/SwiftfulThinking/SwiftfulRoutingExample ## Overview SwiftUI is a declarative framework, and therefore, a SwiftUI router should be declarative by nature. Routers based on programatic code do not declare the view heirarchy in advance, but rather at the time of execution. The solution is to declare all modifiers to support the routing in advance. ## Under the hood As you segue to a new screen, the framework adds a set ViewModifers to the root of the destination View that will support all potential navigation routes. The framework can support 1 active Segue, 1 active Alert, and 1 active Modal on each View in the heirarchy. The ViewModifiers are based on generic and/or type-erased destinations, which maintains a declarative view heirarchy while allowing the developer to still determine the destination at the time of execution. ## Architecture Version 3.0+ return the ViewModifiers back to the segue's call-site as AnyRouter, which further enables the developer to inject the routing logic into the View. See sample project for UI Tests and examples of MVC, MVVM and VIPER design patterns. ## Setup Add the package to your xcode project ``` https://github.com/SwiftfulThinking/SwiftfulRouting.git ``` Import the package ```swift import SwiftfulRouting ``` Add a `RouterView` at the top of your view heirarchy. A `RouterView` will embed your view into a Navigation heirarchy and add modifiers to support all potential segues. Use the returned `router` to perform navigation. ```swift struct ContentView: View { var body: some View { RouterView { router in MyView(router: router) } } } ``` Each `Router` object can simultaneously support 1 active Segue, 1 active Alert, and 1 active Modal. A new Router is created and added to the view heirarchy after each Segue. ```swift struct MyView: View { let router: AnyRouter var body: some View { VStack { Text("Segue") .onTapGesture { router.showScreen(.push) { router in ThirdView(router: router) } } Text("Alert") .onTapGesture { router.showAlert(.alert, title: "Title") { Button("OK") { } Button("Cancel") { } } } Text("Modal") .onTapGesture { router.showModal { ChildView() } } } } } ``` ## Usage The returned router is a type-erased `Router`, named `AnyRouter`. Refer to `AnyRouter.swift` to see all accessible methods. ## RouterView Use RouterView to enter the framework's view heirarchy and use the returned `router: AnyRouter` to perform navigation. ```swift RouterView { router in MyView(router: router) } ``` Be default, your view will be wrapped in with navigation heirarchy (iOS 16+ uses a NavigationStack, iOS 15 and below uses NavigationView). - If your view is already within a navigation heirarchy, set `addNavigationView` to `FALSE`. - If your view is within a NavigationStack, use `screens` to bind to the existing stack path. - The framework uses the native SwiftUI navigation bar, so all related modifiers will still work. ```swift RouterView(addNavigationView: false, screens: $existingStack) { router in MyView(router: router) .navigationBarHidden(true) .toolbar { } } ``` ## Segues Router supports native SwiftUI segues, including .push (NavigationLink), .sheet, and .fullScreenCover. - You may use `router.dismissScreen()` or native SwiftUI environment variables to dismiss the screen. ```swift router.showScreen(.push, destination: (AnyRouter) -> View) router.showScreen(.sheet, destination: (AnyRouter) -> View) router.showScreen(.fullScreenCover, destination: (AnyRouter) -> View) router.dismissScreen() ``` iOS 16 also supports NavigationStack and resizable Sheets. Note that `popToRoot` purposely dismisses all views pushed onto the NavigationStack, but does not dismiss `.sheet` or `.fullScreenCover`. ```swift router.pushScreens(destinations: [(AnyRouter) -> any View] router.popToRoot() router.showResizableSheeet(sheetDetents: Detent, selection: Binding, showDragIndicator: Bool, destination: (AnyRouter) -> View) ``` Additional segues: ```swift router.showSafari(_ url: () -> URL) ``` ## Alerts Router supports native SwiftUI alerts, including `.alert` and `.confirmationDialog`. ```swift router.showAlert(.alert, title: String, subtitle: String?, alert: () -> View) router.showAlert(.confirmationDialog, title: String, subtitle: String?, alert: () -> View) router.dismissAlert() ``` Additional convenience methods: ```swift router.showBasicAlert(text: String, action: (() -> Void)?) ``` ## Modals Router also supports any modal transition, which displays above the current content. Customize transition, animation, background color/blur, etc. ```swift router.showModal(destination: () -> View) router.showModal( transition: AnyTransition, animation: Animation, alignment: Alignment, backgroundColor: Color?, backgroundEffect: BackgroundEffect?, useDeviceBounds: Bool, destination: () -> View) router.dismissModal() ``` Additional convenience methods: ```swift router.showBasicModal(destination: () -> View) ``` ## Contribute Community contributions are encouraged! Please ensure that your code adheres to the project's existing coding style and structure. Most new features are likely to be derivatives of existing features, so many of the existing ViewModifiers and Bindings should be reused. - [Open an issue](https://github.com/SwiftfulThinking/SwiftfulRouting/issues) for issues with the existing codebase. - [Open a discussion](https://github.com/SwiftfulThinking/SwiftfulRouting/discussions) for new feature requests. - [Submit a pull request](https://github.com/SwiftfulThinking/SwiftfulRouting/pulls) when the feature is ready.

近期下载者

相关文件


收藏者