├── demo.gif ├── Example ├── Example │ ├── Assets.xcassets │ │ ├── Contents.json │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Preview Content │ │ └── Preview Assets.xcassets │ │ │ └── Contents.json │ ├── ExampleApp.swift │ ├── Example.entitlements │ ├── Info.plist │ ├── ChildView.swift │ └── ContentView.swift └── Example.xcodeproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── project.pbxproj ├── Tests ├── LinuxMain.swift └── StackNavigationViewTests │ ├── XCTestManifests.swift │ └── StackNavigationViewTests.swift ├── .swiftpm └── xcode │ └── package.xcworkspace │ └── contents.xcworkspacedata ├── Sources └── StackNavigationView │ ├── ModalView.swift │ ├── CurrentView.swift │ ├── Environment.swift │ ├── StackNavigationView.swift │ └── NavigationLink.swift ├── LICENSE ├── Package.swift └── README.md /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbrndnr/StackNavigationView/HEAD/demo.gif -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Example/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import StackNavigationViewTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += StackNavigationViewTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tests/StackNavigationViewTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(StackNavigationViewTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /Example/Example/ExampleApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleApp.swift 3 | // Example 4 | // 5 | // Created by Laurin Brandner on 05.01.21. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct ExampleApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example/Example.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Sources/StackNavigationView/ModalView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ModalView.swift 3 | // Nuage 4 | // 5 | // Created by Laurin Brandner on 11.01.21. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ModalView: Equatable { 11 | 12 | var item: Binding 13 | var content: AnyView 14 | 15 | static func == (lhs: ModalView, rhs: ModalView) -> Bool { lhs.item.wrappedValue == rhs.item.wrappedValue } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Sources/StackNavigationView/CurrentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CurrentView.swift 3 | // 4 | // 5 | // Created by Laurin Brandner on 02.01.21. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct CurrentView: View { 11 | 12 | @Environment(\.currentView) private var currentView: AnyView? 13 | 14 | private var defaultView: AnyView 15 | 16 | var body: some View { currentView ?? defaultView } 17 | 18 | init(defaultView: Content) { 19 | self.defaultView = AnyView(defaultView) 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Tests/StackNavigationViewTests/StackNavigationViewTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import StackNavigationView 3 | 4 | final class StackNavigationViewTests: XCTestCase { 5 | func testExample() { 6 | // This is an example of a functional test case. 7 | // Use XCTAssert and related functions to verify your tests produce the correct 8 | // results. 9 | XCTAssertEqual(StackNavigationView().text, "Hello, World!") 10 | } 11 | 12 | static var allTests = [ 13 | ("testExample", testExample), 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSMinimumSystemVersion 22 | $(MACOSX_DEPLOYMENT_TARGET) 23 | 24 | 25 | -------------------------------------------------------------------------------- /Sources/StackNavigationView/Environment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Environment.swift 3 | // 4 | // 5 | // Created by Laurin Brandner on 02.01.21. 6 | // 7 | 8 | import SwiftUI 9 | 10 | typealias Push = (AnyView, Any?) -> () 11 | struct PushKey: EnvironmentKey { 12 | 13 | static let defaultValue: Push = { _, _ in } 14 | 15 | } 16 | 17 | struct CurrentViewKey: EnvironmentKey { 18 | 19 | static let defaultValue: AnyView? = nil 20 | 21 | } 22 | 23 | struct ModalViewKey: EnvironmentKey { 24 | 25 | static let defaultValue: ModalView? = nil 26 | 27 | } 28 | 29 | extension EnvironmentValues { 30 | 31 | var push: Push { 32 | get { self[PushKey.self] } 33 | set { self[PushKey.self] = newValue } 34 | } 35 | 36 | var currentView: AnyView? { 37 | get { self[CurrentViewKey.self] } 38 | set { self[CurrentViewKey.self] = newValue } 39 | } 40 | 41 | var modalView: ModalView? { 42 | get { self[ModalViewKey.self] } 43 | set { self[ModalViewKey.self] = newValue } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Laurin Brandner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Example/Example/ChildView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChildView.swift 3 | // Example 4 | // 5 | // Created by Laurin Brandner on 05.01.21. 6 | // 7 | 8 | import SwiftUI 9 | import StackNavigationView 10 | 11 | struct ChildView: View { 12 | 13 | private var sidebar: String 14 | private var level: Int 15 | 16 | var body: some View { 17 | VStack { 18 | Text("This is level \(level) in \(sidebar)") 19 | .font(.system(size: 50)) 20 | .bold() 21 | Text("Hit next to proceed to level \(level+1)") 22 | .font(.system(size: 20)) 23 | Spacer() 24 | .frame(height: 40) 25 | StackNavigationLink("Next", destination: ChildView(sidebar: sidebar, level: level+1)) 26 | } 27 | .padding(20) 28 | .navigationTitle("Detail \(level)") 29 | } 30 | 31 | init(sidebar: String, level: Int) { 32 | self.sidebar = sidebar 33 | self.level = level 34 | } 35 | 36 | } 37 | 38 | struct ChildView_Previews: PreviewProvider { 39 | static var previews: some View { 40 | ChildView(sidebar: "AAA", level: 3) 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "scale" : "1x", 6 | "size" : "16x16" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "scale" : "2x", 11 | "size" : "16x16" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "scale" : "1x", 16 | "size" : "32x32" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "scale" : "2x", 21 | "size" : "32x32" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "scale" : "1x", 26 | "size" : "128x128" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "scale" : "2x", 31 | "size" : "128x128" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "scale" : "1x", 36 | "size" : "256x256" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "scale" : "2x", 41 | "size" : "256x256" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "scale" : "1x", 46 | "size" : "512x512" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "scale" : "2x", 51 | "size" : "512x512" 52 | } 53 | ], 54 | "info" : { 55 | "author" : "xcode", 56 | "version" : 1 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "StackNavigationView", 8 | platforms: [.macOS(.v11)], 9 | products: [ 10 | // Products define the executables and libraries a package produces, and make them visible to other packages. 11 | .library( 12 | name: "StackNavigationView", 13 | targets: ["StackNavigationView"]), 14 | ], 15 | dependencies: [ 16 | // Dependencies declare other packages that this package depends on. 17 | // .package(url: /* package url */, from: "1.0.0"), 18 | ], 19 | targets: [ 20 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 21 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 22 | .target( 23 | name: "StackNavigationView", 24 | dependencies: []), 25 | .testTarget( 26 | name: "StackNavigationViewTests", 27 | dependencies: ["StackNavigationView"]), 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /Example/Example/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // Example 4 | // 5 | // Created by Laurin Brandner on 05.01.21. 6 | // 7 | 8 | import SwiftUI 9 | import StackNavigationView 10 | 11 | struct ContentView: View { 12 | 13 | @State private var selection: Int? = 0 14 | 15 | var body: some View { 16 | 17 | return StackNavigationView(selection: $selection) { 18 | List { 19 | SidebarNavigationLink("Apples", destination: rootView(title: "Apples"), tag: 0, selection: $selection) 20 | SidebarNavigationLink("Bananas", destination: rootView(title: "Bananas"), tag: 1, selection: $selection) 21 | SidebarNavigationLink("Clementines", destination: rootView(title: "Clementines"), tag: 2, selection: $selection) 22 | } 23 | Text("Empty Selection") 24 | } 25 | .frame(minWidth: 600, minHeight: 400) 26 | } 27 | 28 | @ViewBuilder private func rootView(title: String) -> some View { 29 | VStack { 30 | Text("This is the root view of \(title)") 31 | .font(.system(size: 50)) 32 | .bold() 33 | Spacer() 34 | .frame(height: 40) 35 | StackNavigationLink("Next", destination: ChildView(sidebar: title, level: 1)) 36 | } 37 | .padding(20) 38 | .navigationTitle(title) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StackNavigationView 2 | 3 | [![Twitter: @lbrndnr](https://img.shields.io/badge/contact-@lbrndnr-blue.svg?style=flat)](https://twitter.com/lbrndnr) 4 | [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/lbrndnr/StackNavigationView/blob/master/LICENSE) 5 | 6 | ⚠️ SwiftUI now supports [NavigationStack](https://developer.apple.com/documentation/swiftui/navigationstack), making this repo redundant for new projects. I recommend to only use this if you have to support macOS 11 or 12. ⚠️ 7 | 8 | ## About 9 | As of SwiftUI v2, `NavigationView` only supports a simple sidebar selection. This makes it impossible to push new views onto the view hierarchy, as one could do e.g. with `UINavigationController`. This project is a workaround that builds upon `NavigationView` to support complex view hierarchies. 10 | 11 | ![Demo](https://raw.githubusercontent.com/lbrndnr/StackNavigationView/master/demo.gif) 12 | 13 | ## Usage 14 | The interface of `StackNavigationView` is very similar to the one of `NavigationView`, just make sure not to use `NavigationLink` inside of `StackNavigationView` though, it will result in undefined behaviour. You'll find the full example [here](https://github.com/lbrndnr/StackNavigationView/tree/master/Example/Example). 15 | 16 | ```swift 17 | struct ContentView: View { 18 | 19 | @State private var selection: Int? = 0 20 | 21 | var body: some View { 22 | 23 | return StackNavigationView(selection: $selection) { 24 | List { 25 | SidebarNavigationLink("Apples", destination: rootView(title: "Apples"), tag: 0, selection: $selection) 26 | SidebarNavigationLink("Bananas", destination: rootView(title: "Bananas"), tag: 1, selection: $selection) 27 | SidebarNavigationLink("Clementines", destination: rootView(title: "Clementines"), tag: 2, selection: $selection) 28 | } 29 | Text("Empty Selection") 30 | } 31 | .frame(minWidth: 600, minHeight: 400) 32 | } 33 | 34 | @ViewBuilder private func rootView(title: String) -> some View { 35 | VStack { 36 | Text("This is the root view of \(title)") 37 | .font(.system(size: 50)) 38 | .bold() 39 | Spacer() 40 | .frame(height: 40) 41 | StackNavigationLink("Next", destination: ChildView(sidebar: title, level: 1)) 42 | } 43 | .padding(20) 44 | .navigationTitle(title) 45 | } 46 | } 47 | ``` 48 | 49 | ## Requirements 50 | `StackNavigationView` is a SwiftUI component for macOS. macOS Big Sur is required. 51 | 52 | ## Author 53 | I'm Laurin Brandner, I'm on [Twitter](https://twitter.com/lbrndnr). 54 | 55 | ## License 56 | `StackNavigationView` is licensed under the [MIT License](http://opensource.org/licenses/mit-license.php). 57 | -------------------------------------------------------------------------------- /Sources/StackNavigationView/StackNavigationView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StackNavigationLink.swift 3 | // 4 | // 5 | // Created by Laurin Brandner on 02.01.21. 6 | // 7 | 8 | import SwiftUI 9 | import Combine 10 | 11 | public struct StackNavigationView: View { 12 | 13 | private var content: Content 14 | 15 | @State private var pushed: [(AnyView?, V?)] 16 | @State private var popped = [(AnyView?, V?)]() 17 | 18 | @Environment(\.modalView) private var modalView: ModalView? 19 | 20 | private var canGoBack: Bool { pushed.count > 1 } 21 | private var canGoForward: Bool { popped.count > 0 } 22 | private var selection: Binding? 23 | 24 | public var body: some View { 25 | NavigationView(content: { content }) 26 | .environment(\.push, push) 27 | .environment(\.currentView, pushed.last?.0) 28 | .onChange(of: modalView) { [modalView] newModal in 29 | modalView?.item.wrappedValue = nil 30 | if let view = newModal?.content { 31 | push(view, tag: nil) 32 | } 33 | } 34 | .toolbar { 35 | ToolbarItem(placement: .navigation) { 36 | Button(action: goBack, label: { 37 | Image(systemName: "chevron.left") 38 | }) 39 | .disabled(!canGoBack) 40 | .keyboardShortcut("[", modifiers: .command) 41 | } 42 | ToolbarItem(placement: .navigation) { 43 | Button(action: goForward, label: { 44 | Image(systemName: "chevron.right") 45 | }) 46 | .disabled(!canGoForward) 47 | .keyboardShortcut("]", modifiers: .command) 48 | } 49 | } 50 | } 51 | 52 | public init(@ViewBuilder content: () -> Content) { 53 | self.content = content() 54 | self._pushed = State(initialValue: []) 55 | } 56 | 57 | public init(selection: Binding, @ViewBuilder content: () -> Content) { 58 | self.content = content() 59 | self.selection = selection 60 | self._pushed = State(initialValue: [(nil, selection.wrappedValue)]) 61 | } 62 | 63 | public func stack(item: Binding, @ViewBuilder content: () -> Content) -> some View { 64 | let content = content().id(UUID()) 65 | return transformEnvironment(\.modalView) { modalView in 66 | if item.wrappedValue != nil { 67 | modalView = ModalView(item: item, content: AnyView(content)) 68 | } 69 | else { 70 | modalView = nil 71 | } 72 | } 73 | } 74 | 75 | private func push(_ content: AnyView, tag: Any?) { 76 | let view = AnyView(content.id(UUID())) 77 | 78 | guard let tag = tag as? V? else { preconditionFailure() } 79 | pushed.append((view, tag)) 80 | popped.removeAll() 81 | if let tag = tag { 82 | selection?.wrappedValue = tag 83 | } 84 | } 85 | 86 | private func goBack() { 87 | guard let (content, tag) = pushed.popLast() else { preconditionFailure() } 88 | popped.append((content, tag)) 89 | if let tag = pushed.last?.1 { 90 | selection?.wrappedValue = tag 91 | } 92 | if let modalView = modalView { 93 | modalView.item.wrappedValue = nil 94 | } 95 | } 96 | 97 | private func goForward() { 98 | guard let (content, tag) = popped.popLast() else { preconditionFailure() } 99 | pushed.append((content, tag)) 100 | if let tag = tag { 101 | selection?.wrappedValue = tag 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /Sources/StackNavigationView/NavigationLink.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NavigationLink.swift 3 | // 4 | // 5 | // Created by Laurin Brandner on 02.01.21. 6 | // 7 | 8 | import SwiftUI 9 | 10 | public struct SidebarNavigationLink : View where Label : View, Destination : View { 11 | 12 | var label: Label 13 | var destination: Destination 14 | var tag: V? 15 | var selection: Binding? 16 | 17 | @Environment(\.push) private var push 18 | 19 | public var body: some View { 20 | if let tag = tag, let selection = selection { 21 | let binding = Binding(get: { selection.wrappedValue }, set: { _ in 22 | push(AnyView(destination), tag) 23 | }) 24 | 25 | NavigationLink(destination: CurrentView(defaultView: destination), tag: tag, selection: binding, label: { label }) 26 | } 27 | } 28 | 29 | /// Creates an instance that presents `destination`. 30 | // public init(destination: Destination, @ViewBuilder label: @escaping () -> Label) where V == Int { 31 | // self.label = label 32 | // self.destination = destination 33 | // } 34 | // 35 | // public init(destination: Destination, isActive: Binding, @ViewBuilder label: @escaping () -> Label) { 36 | // self.label = label 37 | // self.destination = destination 38 | // } 39 | // 40 | /// Creates an instance that presents `destination` when `selection` is set 41 | /// to `tag`. 42 | public init(destination: Destination, tag: V, selection: Binding, @ViewBuilder label: () -> Label) where V : Hashable { 43 | self.label = label() 44 | self.destination = destination 45 | self.tag = tag 46 | self.selection = selection 47 | } 48 | 49 | } 50 | 51 | extension SidebarNavigationLink where Label == Text { 52 | 53 | // /// Creates an instance that presents `destination`, with a `Text` label 54 | // /// generated from a title string. 55 | // public init(_ titleKey: LocalizedStringKey, destination: Destination) 56 | // 57 | // /// Creates an instance that presents `destination`, with a `Text` label 58 | // /// generated from a title string. 59 | // public init(_ title: S, destination: Destination) where S : StringProtocol 60 | // 61 | // /// Creates an instance that presents `destination` when active, with a 62 | // /// `Text` label generated from a title string. 63 | // public init(_ titleKey: LocalizedStringKey, destination: Destination, isActive: Binding) 64 | // 65 | // /// Creates an instance that presents `destination` when active, with a 66 | // /// `Text` label generated from a title string. 67 | // public init(_ title: S, destination: Destination, isActive: Binding) where S : StringProtocol 68 | // 69 | // /// Creates an instance that presents `destination` when `selection` is set 70 | // /// to `tag`, with a `Text` label generated from a title string. 71 | // public init(_ titleKey: LocalizedStringKey, destination: Destination, tag: V, selection: Binding) where V : Hashable 72 | 73 | /// Creates an instance that presents `destination` when `selection` is set 74 | /// to `tag`, with a `Text` label generated from a title string. 75 | public init(_ title: S, destination: Destination, tag: V, selection: Binding) where S : StringProtocol { 76 | self.label = Text(title) 77 | self.destination = destination 78 | self.tag = tag 79 | self.selection = selection 80 | } 81 | 82 | } 83 | 84 | public struct StackNavigationLink: View { 85 | 86 | private var label: Label 87 | private var destination: Destination 88 | private var wrapInButton = false 89 | 90 | @Environment(\.push) private var push 91 | 92 | public var body: some View { 93 | let action = { 94 | self.push(AnyView(destination), nil) 95 | } 96 | 97 | if wrapInButton { 98 | Button(action: action, label: { label }) 99 | } 100 | else { 101 | label.onTapGesture(perform: action) 102 | } 103 | } 104 | 105 | /// Creates an instance that presents `destination`. 106 | public init(destination: Destination, @ViewBuilder label: () -> Label) { 107 | self.label = label() 108 | self.destination = destination 109 | } 110 | // 111 | // public init(destination: Destination, isActive: Binding, @ViewBuilder label: @escaping () -> Label) { 112 | // self.label = label 113 | // self.destination = destination 114 | // } 115 | // 116 | // /// Creates an instance that presents `destination` when `selection` is set 117 | // /// to `tag`. 118 | // public init(destination: Destination, tag: V, selection: Binding, @ViewBuilder label: @escaping () -> Label) where V : Hashable { 119 | // self.label = label 120 | // self.destination = destination 121 | // } 122 | 123 | } 124 | 125 | extension StackNavigationLink where Label == Text { 126 | 127 | // /// Creates an instance that presents `destination`, with a `Text` label 128 | // /// generated from a title string. 129 | // public init(_ titleKey: LocalizedStringKey, destination: Destination) 130 | // 131 | // /// Creates an instance that presents `destination`, with a `Text` label 132 | // /// generated from a title string. 133 | // public init(_ title: S, destination: Destination) where S : StringProtocol 134 | // 135 | // /// Creates an instance that presents `destination` when active, with a 136 | // /// `Text` label generated from a title string. 137 | // public init(_ titleKey: LocalizedStringKey, destination: Destination, isActive: Binding) 138 | // 139 | // /// Creates an instance that presents `destination` when active, with a 140 | // /// `Text` label generated from a title string. 141 | // public init(_ title: S, destination: Destination, isActive: Binding) where S : StringProtocol 142 | // 143 | // /// Creates an instance that presents `destination` when `selection` is set 144 | // /// to `tag`, with a `Text` label generated from a title string. 145 | // public init(_ titleKey: LocalizedStringKey, destination: Destination, tag: V, selection: Binding) where V : Hashable 146 | 147 | /// Creates an instance that presents `destination` when `selection` is set 148 | /// to `tag`, with a `Text` label generated from a title string. 149 | public init(_ title: S, destination: Destination) where S : StringProtocol { 150 | self.label = Text(title) 151 | self.destination = destination 152 | self.wrapInButton = true 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4963631F25A4FC3700C7F1AF /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4963631E25A4FC3700C7F1AF /* ExampleApp.swift */; }; 11 | 4963632125A4FC3700C7F1AF /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4963632025A4FC3700C7F1AF /* ContentView.swift */; }; 12 | 4963632325A4FC3800C7F1AF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4963632225A4FC3800C7F1AF /* Assets.xcassets */; }; 13 | 4963632625A4FC3800C7F1AF /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4963632525A4FC3800C7F1AF /* Preview Assets.xcassets */; }; 14 | 4963633525A5013C00C7F1AF /* StackNavigationView in Frameworks */ = {isa = PBXBuildFile; productRef = 4963633425A5013C00C7F1AF /* StackNavigationView */; }; 15 | 4963633825A501BF00C7F1AF /* ChildView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4963633725A501BF00C7F1AF /* ChildView.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 4963631B25A4FC3700C7F1AF /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 4963631E25A4FC3700C7F1AF /* ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleApp.swift; sourceTree = ""; }; 21 | 4963632025A4FC3700C7F1AF /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 22 | 4963632225A4FC3800C7F1AF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 4963632525A4FC3800C7F1AF /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 24 | 4963632725A4FC3800C7F1AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | 4963632825A4FC3800C7F1AF /* Example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Example.entitlements; sourceTree = ""; }; 26 | 4963633725A501BF00C7F1AF /* ChildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChildView.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 4963631825A4FC3700C7F1AF /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | 4963633525A5013C00C7F1AF /* StackNavigationView in Frameworks */, 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | 4963631225A4FC3700C7F1AF = { 42 | isa = PBXGroup; 43 | children = ( 44 | 4963631D25A4FC3700C7F1AF /* Example */, 45 | 4963631C25A4FC3700C7F1AF /* Products */, 46 | ); 47 | sourceTree = ""; 48 | }; 49 | 4963631C25A4FC3700C7F1AF /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | 4963631B25A4FC3700C7F1AF /* Example.app */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | 4963631D25A4FC3700C7F1AF /* Example */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 4963631E25A4FC3700C7F1AF /* ExampleApp.swift */, 61 | 4963632025A4FC3700C7F1AF /* ContentView.swift */, 62 | 4963633725A501BF00C7F1AF /* ChildView.swift */, 63 | 4963632225A4FC3800C7F1AF /* Assets.xcassets */, 64 | 4963632725A4FC3800C7F1AF /* Info.plist */, 65 | 4963632825A4FC3800C7F1AF /* Example.entitlements */, 66 | 4963632425A4FC3800C7F1AF /* Preview Content */, 67 | ); 68 | path = Example; 69 | sourceTree = ""; 70 | }; 71 | 4963632425A4FC3800C7F1AF /* Preview Content */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 4963632525A4FC3800C7F1AF /* Preview Assets.xcassets */, 75 | ); 76 | path = "Preview Content"; 77 | sourceTree = ""; 78 | }; 79 | /* End PBXGroup section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | 4963631A25A4FC3700C7F1AF /* Example */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = 4963632B25A4FC3800C7F1AF /* Build configuration list for PBXNativeTarget "Example" */; 85 | buildPhases = ( 86 | 4963631725A4FC3700C7F1AF /* Sources */, 87 | 4963631825A4FC3700C7F1AF /* Frameworks */, 88 | 4963631925A4FC3700C7F1AF /* Resources */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = Example; 95 | packageProductDependencies = ( 96 | 4963633425A5013C00C7F1AF /* StackNavigationView */, 97 | ); 98 | productName = Example; 99 | productReference = 4963631B25A4FC3700C7F1AF /* Example.app */; 100 | productType = "com.apple.product-type.application"; 101 | }; 102 | /* End PBXNativeTarget section */ 103 | 104 | /* Begin PBXProject section */ 105 | 4963631325A4FC3700C7F1AF /* Project object */ = { 106 | isa = PBXProject; 107 | attributes = { 108 | LastSwiftUpdateCheck = 1230; 109 | LastUpgradeCheck = 1230; 110 | TargetAttributes = { 111 | 4963631A25A4FC3700C7F1AF = { 112 | CreatedOnToolsVersion = 12.3; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = 4963631625A4FC3700C7F1AF /* Build configuration list for PBXProject "Example" */; 117 | compatibilityVersion = "Xcode 9.3"; 118 | developmentRegion = en; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | Base, 123 | ); 124 | mainGroup = 4963631225A4FC3700C7F1AF; 125 | packageReferences = ( 126 | 4963633325A5013C00C7F1AF /* XCRemoteSwiftPackageReference "StackNavigationView" */, 127 | ); 128 | productRefGroup = 4963631C25A4FC3700C7F1AF /* Products */; 129 | projectDirPath = ""; 130 | projectRoot = ""; 131 | targets = ( 132 | 4963631A25A4FC3700C7F1AF /* Example */, 133 | ); 134 | }; 135 | /* End PBXProject section */ 136 | 137 | /* Begin PBXResourcesBuildPhase section */ 138 | 4963631925A4FC3700C7F1AF /* Resources */ = { 139 | isa = PBXResourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | 4963632625A4FC3800C7F1AF /* Preview Assets.xcassets in Resources */, 143 | 4963632325A4FC3800C7F1AF /* Assets.xcassets in Resources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXResourcesBuildPhase section */ 148 | 149 | /* Begin PBXSourcesBuildPhase section */ 150 | 4963631725A4FC3700C7F1AF /* Sources */ = { 151 | isa = PBXSourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | 4963632125A4FC3700C7F1AF /* ContentView.swift in Sources */, 155 | 4963631F25A4FC3700C7F1AF /* ExampleApp.swift in Sources */, 156 | 4963633825A501BF00C7F1AF /* ChildView.swift in Sources */, 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXSourcesBuildPhase section */ 161 | 162 | /* Begin XCBuildConfiguration section */ 163 | 4963632925A4FC3800C7F1AF /* Debug */ = { 164 | isa = XCBuildConfiguration; 165 | buildSettings = { 166 | ALWAYS_SEARCH_USER_PATHS = NO; 167 | CLANG_ANALYZER_NONNULL = YES; 168 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 169 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 170 | CLANG_CXX_LIBRARY = "libc++"; 171 | CLANG_ENABLE_MODULES = YES; 172 | CLANG_ENABLE_OBJC_ARC = YES; 173 | CLANG_ENABLE_OBJC_WEAK = YES; 174 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 175 | CLANG_WARN_BOOL_CONVERSION = YES; 176 | CLANG_WARN_COMMA = YES; 177 | CLANG_WARN_CONSTANT_CONVERSION = YES; 178 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 179 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 180 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 181 | CLANG_WARN_EMPTY_BODY = YES; 182 | CLANG_WARN_ENUM_CONVERSION = YES; 183 | CLANG_WARN_INFINITE_RECURSION = YES; 184 | CLANG_WARN_INT_CONVERSION = YES; 185 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 186 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 187 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 189 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 190 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 191 | CLANG_WARN_STRICT_PROTOTYPES = YES; 192 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 193 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 194 | CLANG_WARN_UNREACHABLE_CODE = YES; 195 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 196 | COPY_PHASE_STRIP = NO; 197 | DEBUG_INFORMATION_FORMAT = dwarf; 198 | ENABLE_STRICT_OBJC_MSGSEND = YES; 199 | ENABLE_TESTABILITY = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu11; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_NO_COMMON_BLOCKS = YES; 203 | GCC_OPTIMIZATION_LEVEL = 0; 204 | GCC_PREPROCESSOR_DEFINITIONS = ( 205 | "DEBUG=1", 206 | "$(inherited)", 207 | ); 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | MACOSX_DEPLOYMENT_TARGET = 11.1; 215 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 216 | MTL_FAST_MATH = YES; 217 | ONLY_ACTIVE_ARCH = YES; 218 | SDKROOT = macosx; 219 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 220 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 221 | }; 222 | name = Debug; 223 | }; 224 | 4963632A25A4FC3800C7F1AF /* Release */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | ALWAYS_SEARCH_USER_PATHS = NO; 228 | CLANG_ANALYZER_NONNULL = YES; 229 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_ENABLE_OBJC_WEAK = YES; 235 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 236 | CLANG_WARN_BOOL_CONVERSION = YES; 237 | CLANG_WARN_COMMA = YES; 238 | CLANG_WARN_CONSTANT_CONVERSION = YES; 239 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 240 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 241 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 242 | CLANG_WARN_EMPTY_BODY = YES; 243 | CLANG_WARN_ENUM_CONVERSION = YES; 244 | CLANG_WARN_INFINITE_RECURSION = YES; 245 | CLANG_WARN_INT_CONVERSION = YES; 246 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 247 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 248 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 250 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 251 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 252 | CLANG_WARN_STRICT_PROTOTYPES = YES; 253 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 254 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 255 | CLANG_WARN_UNREACHABLE_CODE = YES; 256 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_NS_ASSERTIONS = NO; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | GCC_C_LANGUAGE_STANDARD = gnu11; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | MACOSX_DEPLOYMENT_TARGET = 11.1; 270 | MTL_ENABLE_DEBUG_INFO = NO; 271 | MTL_FAST_MATH = YES; 272 | SDKROOT = macosx; 273 | SWIFT_COMPILATION_MODE = wholemodule; 274 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 275 | }; 276 | name = Release; 277 | }; 278 | 4963632C25A4FC3800C7F1AF /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 282 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 283 | CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements; 284 | CODE_SIGN_STYLE = Automatic; 285 | COMBINE_HIDPI_IMAGES = YES; 286 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 287 | ENABLE_PREVIEWS = YES; 288 | INFOPLIST_FILE = Example/Info.plist; 289 | LD_RUNPATH_SEARCH_PATHS = ( 290 | "$(inherited)", 291 | "@executable_path/../Frameworks", 292 | ); 293 | MACOSX_DEPLOYMENT_TARGET = 11.0; 294 | PRODUCT_BUNDLE_IDENTIFIER = laurinbrandner.Example; 295 | PRODUCT_NAME = "$(TARGET_NAME)"; 296 | SWIFT_VERSION = 5.0; 297 | }; 298 | name = Debug; 299 | }; 300 | 4963632D25A4FC3800C7F1AF /* Release */ = { 301 | isa = XCBuildConfiguration; 302 | buildSettings = { 303 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 304 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 305 | CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements; 306 | CODE_SIGN_STYLE = Automatic; 307 | COMBINE_HIDPI_IMAGES = YES; 308 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 309 | ENABLE_PREVIEWS = YES; 310 | INFOPLIST_FILE = Example/Info.plist; 311 | LD_RUNPATH_SEARCH_PATHS = ( 312 | "$(inherited)", 313 | "@executable_path/../Frameworks", 314 | ); 315 | MACOSX_DEPLOYMENT_TARGET = 11.0; 316 | PRODUCT_BUNDLE_IDENTIFIER = laurinbrandner.Example; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_VERSION = 5.0; 319 | }; 320 | name = Release; 321 | }; 322 | /* End XCBuildConfiguration section */ 323 | 324 | /* Begin XCConfigurationList section */ 325 | 4963631625A4FC3700C7F1AF /* Build configuration list for PBXProject "Example" */ = { 326 | isa = XCConfigurationList; 327 | buildConfigurations = ( 328 | 4963632925A4FC3800C7F1AF /* Debug */, 329 | 4963632A25A4FC3800C7F1AF /* Release */, 330 | ); 331 | defaultConfigurationIsVisible = 0; 332 | defaultConfigurationName = Release; 333 | }; 334 | 4963632B25A4FC3800C7F1AF /* Build configuration list for PBXNativeTarget "Example" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | 4963632C25A4FC3800C7F1AF /* Debug */, 338 | 4963632D25A4FC3800C7F1AF /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | /* End XCConfigurationList section */ 344 | 345 | /* Begin XCRemoteSwiftPackageReference section */ 346 | 4963633325A5013C00C7F1AF /* XCRemoteSwiftPackageReference "StackNavigationView" */ = { 347 | isa = XCRemoteSwiftPackageReference; 348 | repositoryURL = "file:///Users/Laurin/Development/Libraries/StackNavigationView"; 349 | requirement = { 350 | branch = master; 351 | kind = branch; 352 | }; 353 | }; 354 | /* End XCRemoteSwiftPackageReference section */ 355 | 356 | /* Begin XCSwiftPackageProductDependency section */ 357 | 4963633425A5013C00C7F1AF /* StackNavigationView */ = { 358 | isa = XCSwiftPackageProductDependency; 359 | package = 4963633325A5013C00C7F1AF /* XCRemoteSwiftPackageReference "StackNavigationView" */; 360 | productName = StackNavigationView; 361 | }; 362 | /* End XCSwiftPackageProductDependency section */ 363 | }; 364 | rootObject = 4963631325A4FC3700C7F1AF /* Project object */; 365 | } 366 | --------------------------------------------------------------------------------