├── .github └── workflows │ ├── Build.yml │ └── Docs.yml ├── .gitignore ├── .gitmodules ├── .swiftpm └── xcode │ ├── package.xcworkspace │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ └── xcschemes │ └── StackTests.xcscheme ├── .vscode └── settings.json ├── LICENSE ├── Package.resolved ├── Package.swift ├── README.md ├── Sources └── SwiftUIStack │ ├── AbstractStack.swift │ ├── AndHashable.swift │ ├── EnvironmentReader.swift │ ├── LinkEnvironmentValues.swift │ ├── Log.swift │ ├── MatchedGeometryEffectIdentifier.swift │ ├── NativeStackDisplay.swift │ ├── Stack.swift │ ├── StackBackground.swift │ ├── StackDisplaying.swift │ ├── StackIdentifier.swift │ ├── StackLink.swift │ ├── StackLookupStragety.swift │ ├── StackPath.swift │ ├── StackTransition+Matched.swift │ ├── StackTransition+Slide.swift │ ├── StackTransition.swift │ ├── StackUnwindLink.swift │ ├── StackedView.swift │ ├── View+stackDestination.swift │ └── _StackContext.swift ├── Stack.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ ├── IDEWorkspaceChecks.plist │ ├── swiftpm │ └── Package.resolved │ └── xcschemes │ └── Stack.xcscheme ├── StackApp ├── Stack.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── swiftpm │ │ │ └── Package.resolved │ └── xcshareddata │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── StackDemoApp.xcscheme ├── StackDemoApp │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── BookFullScreenStack.swift │ ├── BookMatchedShape.swift │ ├── BookNavigationStack.swift │ ├── BookNesting.swift │ ├── BookStack.swift │ ├── BookStackNoPath.swift │ ├── BookStack_Grid.swift │ ├── Colors.swift │ ├── ContentView.swift │ ├── Instagram │ │ ├── IGAppRoot.swift │ │ └── IGTabView.swift │ ├── Launch Screen.storyboard │ ├── Model.swift │ ├── Preview Content │ │ └── Preview Assets.xcassets │ │ │ └── Contents.json │ ├── StatefulPage.swift │ └── Views.swift ├── StackDemoAppTests │ └── StackDemoAppTests.swift └── StackDemoAppUITests │ ├── StackDemoAppUITests.swift │ └── StackDemoAppUITestsLaunchTests.swift └── Tests └── SwiftUIStackTests ├── Model.swift └── StackTests.swift /.github/workflows/Build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: "*" 6 | pull_request: 7 | branches: "*" 8 | 9 | jobs: 10 | build: 11 | runs-on: macos-13 12 | 13 | steps: 14 | - uses: maxim-lobanov/setup-xcode@v1.1 15 | with: 16 | xcode-version: "14.3" 17 | - uses: actions/checkout@v2 18 | - name: xcodebuild 19 | run: xcodebuild -scheme SwiftUIStack -sdk iphoneos -destination 'generic/platform=iOS' 20 | 21 | test: 22 | runs-on: macos-13 23 | 24 | steps: 25 | - uses: maxim-lobanov/setup-xcode@v1.1 26 | with: 27 | xcode-version: "14.3" 28 | - uses: actions/checkout@v2 29 | 30 | - name: Test 31 | run: xcodebuild -scheme SwiftUIStackTests -resultBundlePath results/SwiftUIStackTests.xcresult test -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=16.4' | xcpretty 32 | 33 | - uses: kishikawakatsumi/xcresulttool@v1 34 | with: 35 | path: | 36 | results/SwiftUIStackTests.xcresult 37 | if: success() || failure() 38 | -------------------------------------------------------------------------------- /.github/workflows/Docs.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - main # Set a branch name to trigger deployment 7 | workflow_dispatch: 8 | 9 | jobs: 10 | deploy: 11 | runs-on: macos-13 12 | concurrency: 13 | group: ${{ github.workflow }}-${{ github.ref }} 14 | steps: 15 | - uses: maxim-lobanov/setup-xcode@v1.1 16 | with: 17 | xcode-version: "14.3" 18 | - uses: actions/checkout@v2 19 | with: 20 | submodules: true # Fetch Hugo themes (true OR recursive) 21 | fetch-depth: 1 22 | - name: Build 23 | run: xcodebuild docbuild -scheme SwiftUIStack -derivedDataPath .build -destination 'generic/platform=iOS' 24 | - name: Generate 25 | run: | 26 | $(xcrun --find docc) process-archive \ 27 | transform-for-static-hosting ".build/Build/Products/Debug-iphoneos/SwiftUIStack.doccarchive" \ 28 | --output-path public \ 29 | --hosting-base-path "swiftui-stack" 30 | - name: Deploy 31 | uses: peaceiris/actions-gh-pages@v3 32 | if: ${{ github.ref == 'refs/heads/main' }} 33 | with: 34 | github_token: ${{ secrets.GITHUB_TOKEN }} 35 | publish_dir: ./public 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm/config/registries.json 8 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 9 | .netrc 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "submodules/swiftui-support"] 2 | path = submodules/swiftui-support 3 | url = https://github.com/FluidGroup/swiftui-support.git 4 | [submodule "submodules/swiftui-snap-dragging-modifier"] 5 | path = submodules/swiftui-snap-dragging-modifier 6 | url = https://github.com/FluidGroup/swiftui-snap-dragging-modifier.git 7 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.swiftpm/xcode/xcshareddata/xcschemes/StackTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "swiftui-gesture-velocity", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/FluidGroup/swiftui-gesture-velocity", 7 | "state" : { 8 | "revision" : "9c83f8995f9e5efc29db2fca4b9ff058283f1603", 9 | "version" : "1.0.0" 10 | } 11 | }, 12 | { 13 | "identity" : "swiftui-snap-dragging-modifier", 14 | "kind" : "remoteSourceControl", 15 | "location" : "https://github.com/FluidGroup/swiftui-snap-dragging-modifier", 16 | "state" : { 17 | "revision" : "f105008910ee03fe50c23954bee98df8caec0ebe", 18 | "version" : "1.1.2" 19 | } 20 | }, 21 | { 22 | "identity" : "swiftui-support", 23 | "kind" : "remoteSourceControl", 24 | "location" : "https://github.com/FluidGroup/swiftui-support", 25 | "state" : { 26 | "revision" : "8ef53190c33bd345e7a95ef504dafe0f85ad9c4d", 27 | "version" : "0.4.1" 28 | } 29 | }, 30 | { 31 | "identity" : "viewinspector", 32 | "kind" : "remoteSourceControl", 33 | "location" : "https://github.com/nalexn/ViewInspector.git", 34 | "state" : { 35 | "revision" : "4effbd9143ab797eb60d2f32d4265c844c980946", 36 | "version" : "0.9.5" 37 | } 38 | } 39 | ], 40 | "version" : 2 41 | } 42 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.7 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: "swiftui-stack", 8 | platforms: [.iOS(.v14)], 9 | products: [ 10 | .library( 11 | name: "SwiftUIStack", 12 | targets: ["SwiftUIStack"] 13 | ), 14 | ], 15 | dependencies: [ 16 | .package(url: "https://github.com/FluidGroup/swiftui-support", from: "0.4.1"), 17 | .package(url: "https://github.com/FluidGroup/swiftui-snap-dragging-modifier", from: "1.1.2"), 18 | .package(url: "https://github.com/nalexn/ViewInspector.git", from: "0.9.2"), 19 | ], 20 | targets: [ 21 | .target( 22 | name: "SwiftUIStack", 23 | dependencies: [ 24 | .product(name: "SwiftUISupport", package: "swiftui-support"), 25 | .product(name: "SwiftUISnapDraggingModifier", package: "swiftui-snap-dragging-modifier"), 26 | ] 27 | ), 28 | .testTarget( 29 | name: "SwiftUIStackTests", 30 | dependencies: ["SwiftUIStack", "ViewInspector"] 31 | ), 32 | ] 33 | ) 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![stack](https://github.com/FluidGroup/swiftui-stack/assets/1888355/58a5ee2f-c44b-4aa1-8254-34a2b59cda1b) 3 | 4 | Custom Stack Navigation for SwiftUI 5 | --- 6 | This library provides a custom container view for SwiftUI that offers an alternative to the standard NavigationStack. It aims to improve the customizability of transitions during screen navigation by moving away from the behaviors of UINavigationController and UINavigationBar. 7 | 8 | Features 9 | --- 10 | - Customizable transitions during screen navigation 11 | - Contextual animations similar to iOS home screen app icons and app screens 12 | - Familiar API to NavigationView and NavigationStack for ease of use 13 | - Path support for restoring previously navigated views 14 | 15 | Getting Started 16 | --- 17 | To use this library, you'll need to work with three main symbols: Stack, StackLink, and StackUnwindLink. 18 | 19 | Example Usage 20 | --- 21 | 1. Import the SwiftUIStack module in your SwiftUI view file: 22 | 23 | ```swift 24 | import SwiftUIStack 25 | ``` 26 | 27 | 2. Use the Stack container in your view hierarchy: 28 | 29 | ```swift 30 | var body: some View { 31 | Stack { 32 | // Your views here... 33 | } 34 | } 35 | ``` 36 | 37 | 3. Create navigation links using StackLink with your desired transition and destination: 38 | 39 | ```swift 40 | StackLink(transition: .slide, value: someValue) { 41 | Text("Navigate to detail view") 42 | } 43 | ``` 44 | 45 | You can also set the matched transition in the transition parameter using a unique identifier and a namespace: 46 | 47 | ```swift 48 | StackLink(transition: .matched(identifier: user.id, in: local), value: someValue) { 49 | Text("Navigate to detail view with matched transition") 50 | } 51 | ``` 52 | 53 | 4. Optionally, use StackUnwindLink to create a navigation link back to the previous view: 54 | 55 | ```swift 56 | StackUnwindLink { 57 | Text("Back to previous view") 58 | } 59 | ``` 60 | 61 | Unwind Context 62 | --- 63 | In stacked views, you can access the unwindContext as an EnvironmentValue. You can pass the unwindContext to a StackUnwindLink. This allows you to explicitly specify the stack that triggers the unwind. 64 | 65 | ```swift 66 | @Environment(\.stackUnwindContext) var unwindContext 67 | 68 | StackUnwindLink(target: .specific(unwindContext)) { 69 | Text("Back to Menu") 70 | } 71 | ``` 72 | 73 | StackUnwindLink Modes 74 | --- 75 | StackUnwindLink now supports different modes for navigation. To navigate back to the root of the target stack, use the .all mode. 76 | 77 | ```swift 78 | StackUnwindLink(mode: .all) { 79 | Text("Back to Root") 80 | } 81 | ``` 82 | 83 | Nested Stacks 84 | --- 85 | This technique is useful for nested stacks when you need to send a message across multiple levels of the hierarchy. By using the unwindContext in conjunction with StackUnwindLink, you can effectively communicate between nested stacks and navigate through different levels of the view hierarchy. 86 | 87 | Installation 88 | --- 89 | This library currently only supports installation via Swift Package Manager. 90 | 91 | To add the package to your project, you can manually add it to your Package.swift file: 92 | 93 | ```swift 94 | dependencies: [ 95 | .package(url: "https://github.com/FluidGroup/swiftui-stack.git", from: "1.0.0") 96 | ] 97 | ``` 98 | 99 | Contributing 100 | --- 101 | (Include instructions for contributing to the project, such as opening issues, submitting pull requests, and any other relevant information) 102 | 103 | License 104 | --- 105 | This project is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for more information. 106 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/AbstractStack.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A view that receives a root view and views for displaying. 4 | /// It's an abstract view that uses a concrete view to display. 5 | /// You may use ``Stack`` for basic stacking. 6 | /// 7 | /// - TODO: 8 | /// - [x] Path 9 | /// - [x] momentary presentation 10 | /// - [ ] Nesting support 11 | /// 12 | /// memo: 13 | /// https://www.avanderlee.com/swiftui/navigationlink-programmatically-binding/ 14 | @MainActor 15 | public struct AbstractStack: View 16 | where Target.Root == ModifiedContent { 17 | 18 | @StateObject private var context: _StackContext 19 | 20 | private let root: Root 21 | 22 | private let pathBinding: Binding? 23 | 24 | @State private var currentPath: StackPath? 25 | 26 | @Namespace var namespace 27 | 28 | public init( 29 | identifier: StackIdentifier? = nil, 30 | @ViewBuilder root: () -> Root 31 | ) where Data == StackPath { 32 | 33 | // TODO: I don't know how to create Binding without data source(State) 34 | // Instead, context uses two way handlings case of Bindings presents or not. 35 | self.pathBinding = nil 36 | self.root = root() 37 | self._context = .init(wrappedValue: .init(identifier: identifier)) 38 | } 39 | 40 | public init( 41 | identifier: StackIdentifier? = nil, 42 | path: Binding, 43 | @ViewBuilder root: () -> Root 44 | ) where Data == StackPath { 45 | 46 | self.pathBinding = path 47 | self.root = root() 48 | self._context = .init(wrappedValue: .init(identifier: identifier)) 49 | } 50 | 51 | public var body: some View { 52 | 53 | // For retrieving if the parent context is there. 54 | EnvironmentReader(keyPath: \.stackContext) { parentContext in 55 | 56 | GeometryReader { proxy in 57 | Target( 58 | root: root.modifier(AbstractStackRootModifier(namespace: namespace)), 59 | stackedViews: context.stackedViews 60 | ) 61 | .frame(maxWidth: .infinity, maxHeight: .infinity) 62 | .environment(\._safeAreaInsets, proxy.safeAreaInsets) 63 | // propagates context to descendants 64 | .environment(\.stackContext, context) 65 | .environment(\.stackNamespaceID, namespace) 66 | // workaround 67 | .environmentObject(context) 68 | .onReceive( 69 | context.$path, 70 | perform: { path in 71 | Log.debug(.stack, "Updated Path : \(path)") 72 | 73 | pathBinding?.wrappedValue = path 74 | self.currentPath = path 75 | } 76 | ) 77 | .onChangeWithPrevious( 78 | of: pathBinding?.wrappedValue, 79 | emitsInitial: true, 80 | perform: { path, _ in 81 | 82 | /* 83 | Updates current stacking with path changes. 84 | */ 85 | guard let path, path != self.currentPath else { return } 86 | 87 | context.receivePathUpdates(path: path) 88 | } 89 | ) 90 | .onChangeWithPrevious(of: parentContext, emitsInitial: true) { parent, _ in 91 | context.set(parent: parent) 92 | } 93 | 94 | } 95 | 96 | } 97 | 98 | } 99 | 100 | } 101 | 102 | public struct AbstractStackRootModifier: ViewModifier { 103 | 104 | let namespace: Namespace.ID 105 | 106 | public func body(content: Content) -> some View { 107 | ZStack { 108 | content 109 | // as ignoring safe-area above, retores the safe-area 110 | .modifier(RestoreSafeAreaModifier()) 111 | } 112 | // bit tricky - for animations to run as fullscreen. 113 | .ignoresSafeArea() 114 | // built-in matched geometry effect, some transitions may use. 115 | .matchedGeometryEffect( 116 | id: MatchedGeometryEffectIdentifiers.EdgeTrailing(content: .root), 117 | in: namespace, 118 | anchor: .trailing, 119 | isSource: false 120 | ) 121 | 122 | } 123 | } 124 | 125 | private enum SafeAreaInsetsKey: EnvironmentKey { 126 | static var defaultValue: SwiftUI.EdgeInsets { 127 | .init() 128 | } 129 | } 130 | 131 | extension EnvironmentValues { 132 | var _safeAreaInsets: EdgeInsets { 133 | get { self[SafeAreaInsetsKey.self] } 134 | set { self[SafeAreaInsetsKey.self] = newValue } 135 | } 136 | } 137 | 138 | struct RestoreSafeAreaModifier: ViewModifier { 139 | 140 | @Environment(\._safeAreaInsets) var safeAreaInsets 141 | 142 | func body(content: Content) -> some View { 143 | content._safeAreaInsets(safeAreaInsets) 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/AndHashable.swift: -------------------------------------------------------------------------------- 1 | 2 | struct AndHashable: Hashable { 3 | 4 | public let a: A 5 | public let b: B 6 | 7 | public init(a: A, b: B) { 8 | self.a = a 9 | self.b = b 10 | } 11 | } 12 | 13 | extension Hashable { 14 | 15 | func concat(_ other: some Hashable) -> some Hashable { 16 | AndHashable(a: self, b: other) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/EnvironmentReader.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct EnvironmentReader: View { 4 | 5 | @Environment var value: Value 6 | private let content: (Value) -> Content 7 | 8 | init( 9 | keyPath: KeyPath, 10 | @ViewBuilder content: @escaping (Value) -> Content) { 11 | self._value = Environment(keyPath) 12 | self.content = content 13 | } 14 | 15 | var body: some View { 16 | content(value) 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/LinkEnvironmentValues.swift: -------------------------------------------------------------------------------- 1 | 2 | public struct LinkEnvironmentValues { 3 | 4 | private var backing: [TypeKey : Any] = [:] 5 | 6 | public subscript(key: K.Type) -> K.Value where K : LinkEnvironmentKey { 7 | get { 8 | guard let value = backing[.init(key)] else { 9 | return K.defaultValue 10 | } 11 | 12 | return value as! K.Value 13 | } 14 | set { 15 | backing[.init(key)] = newValue 16 | } 17 | } 18 | 19 | } 20 | 21 | public protocol LinkEnvironmentKey { 22 | 23 | associatedtype Value 24 | 25 | static var defaultValue: Self.Value { get } 26 | } 27 | 28 | extension LinkEnvironmentValues { 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/Log.swift: -------------------------------------------------------------------------------- 1 | import os.log 2 | 3 | enum Log { 4 | 5 | static func debug( 6 | file: StaticString = #file, 7 | line: UInt = #line, 8 | _ log: OSLog, 9 | _ object: @autoclosure () -> Any 10 | ) { 11 | os_log(.default, log: log, "%{public}@\n%{public}@:%{public}@", "\(object())", "\(file)", "\(line.description)") 12 | } 13 | 14 | static func error( 15 | file: StaticString = #file, 16 | line: UInt = #line, 17 | _ log: OSLog, 18 | _ object: @autoclosure () -> Any 19 | ) { 20 | os_log(.error, log: log, "%{public}@\n%{public}@:%{public}@", "\(object())", "\(file)", "\(line.description)") 21 | } 22 | 23 | } 24 | 25 | extension OSLog { 26 | 27 | @inline(__always) 28 | private static func makeOSLogInDebug(isEnabled: Bool = true, _ factory: () -> OSLog) -> OSLog { 29 | #if DEBUG 30 | return factory() 31 | #else 32 | return .disabled 33 | #endif 34 | } 35 | 36 | static let `default`: OSLog = makeOSLogInDebug { OSLog.init(subsystem: "", category: "") } 37 | static let environment: OSLog = makeOSLogInDebug { 38 | OSLog.init(subsystem: "Book", category: "environment") 39 | } 40 | 41 | static let `stack`: OSLog = makeOSLogInDebug { OSLog.init(subsystem: "stack", category: "default") } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/MatchedGeometryEffectIdentifier.swift: -------------------------------------------------------------------------------- 1 | 2 | enum MatchedGeometryEffectIdentifiers { 3 | 4 | struct EdgeTrailing: Hashable { 5 | 6 | public enum Content: Hashable { 7 | case root 8 | case stacked(_StackedViewIdentifier) 9 | } 10 | 11 | let content: Content 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/NativeStackDisplay.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A view that displays stacked views in all SwiftUI. 4 | public struct NativeStackDisplay: View, StackDisplaying { 5 | 6 | @Environment(\.stackNamespaceID) var namespaceID 7 | 8 | let root: Root 9 | let stackedViews: [StackedView] 10 | 11 | public init( 12 | root: Root, 13 | stackedViews: [StackedView] 14 | ) { 15 | self.root = root 16 | self.stackedViews = stackedViews 17 | } 18 | 19 | public var body: some View { 20 | ZStack { 21 | 22 | VStack { 23 | root 24 | } 25 | 26 | ForEach(stackedViews) { view in 27 | view 28 | .zIndex(1) // https://sarunw.com/posts/how-to-fix-zstack-transition-animation-in-swiftui/ 29 | } 30 | .ignoresSafeArea() 31 | 32 | } 33 | .frame(maxWidth: .infinity, maxHeight: .infinity) 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/Stack.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A typealias a Stack using ``NativeStack`` 4 | public typealias Stack = AbstractStack>> 5 | 6 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackBackground.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /** 4 | A view that displays background view correctly in ``Stack`` 5 | */ 6 | public struct StackBackground: View { 7 | 8 | let content: Content 9 | @Environment(\._safeAreaInsets) var safeAreaInsets 10 | 11 | public init( 12 | @ViewBuilder content: () -> Content 13 | ) { 14 | self.content = content() 15 | } 16 | 17 | public var body: some View { 18 | 19 | let safeAreaInsets = self.safeAreaInsets 20 | 21 | content 22 | .padding(.top, -safeAreaInsets.top) 23 | .padding(.bottom, -safeAreaInsets.bottom) 24 | .padding(.leading, -safeAreaInsets.leading) 25 | .padding(.trailing, -safeAreaInsets.trailing) 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackDisplaying.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | public protocol StackDisplaying: View { 4 | 5 | associatedtype Root: View 6 | 7 | init( 8 | root: Root, 9 | stackedViews: [StackedView] 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackIdentifier.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | public struct StackIdentifier: Hashable { 4 | 5 | public let rawValue: String 6 | 7 | public init(_ rawValue: String) { 8 | self.rawValue = rawValue 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackLink.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /** 4 | A view that controls a stack presentation 5 | 6 | ```swift 7 | Stack { 8 | 9 | List { 10 | StackLink(value: Color.pink) { 11 | ColorDisplay(color: Color.pink) 12 | } 13 | } 14 | .stackDestination(for: Color.self) { color in 15 | ColorDetail(color: color) 16 | } 17 | 18 | } 19 | ``` 20 | */ 21 | public struct StackLink: View { 22 | 23 | // to trigger update entirely 24 | @EnvironmentObject private var dummy_context: _StackContext 25 | 26 | @Environment(\.stackContext) private var context 27 | @Environment(\.stackNamespaceID) private var namespaceID 28 | 29 | /// pushing or not 30 | @State var isActive = false 31 | @State var currentIdentifier: _StackedViewIdentifier? 32 | 33 | private let target: StackLookupStragety 34 | private let label: Label 35 | private let value: (any Hashable)? 36 | private let destination: Destination? 37 | private let transition: Transition 38 | 39 | private var linkEnvironments: LinkEnvironmentValues = .init() 40 | 41 | public init( 42 | target: StackLookupStragety = .current, 43 | transition: Transition, 44 | value: Value?, 45 | @ViewBuilder label: () -> Label 46 | ) where Destination == Never { 47 | self.target = target 48 | self.label = label() 49 | self.value = value 50 | self.destination = nil 51 | self.transition = transition 52 | } 53 | 54 | public init( 55 | target: StackLookupStragety = .current, 56 | value: Value?, 57 | @ViewBuilder label: () -> Label 58 | ) where Destination == Never, Transition == StackTransitions.Basic { 59 | self.init( 60 | target: target, 61 | transition: StackTransitions.Basic(transition: .opacity.animation(.spring())), 62 | value: value, 63 | label: label 64 | ) 65 | } 66 | 67 | public init( 68 | target: StackLookupStragety = .current, 69 | transition: Transition, 70 | @ViewBuilder destination: () -> Destination, 71 | @ViewBuilder label: () -> Label 72 | ) { 73 | self.target = target 74 | self.label = label() 75 | self.destination = destination() 76 | self.value = nil 77 | self.transition = transition 78 | } 79 | 80 | public init( 81 | target: StackLookupStragety = .current, 82 | @ViewBuilder destination: () -> Destination, 83 | @ViewBuilder label: () -> Label 84 | ) where Transition == StackTransitions.Basic { 85 | self.init( 86 | target: target, 87 | transition: StackTransitions.Basic(transition: .opacity.animation(.spring())), 88 | destination: destination, 89 | label: label 90 | ) 91 | } 92 | 93 | // content for label 94 | public var body: some View { 95 | Button { 96 | 97 | // guard currentIdentifier == nil else { return } 98 | 99 | guard let context = context?.lookup(strategy: target) else { 100 | Log.error(.stack, "Attempted to push view in Stack, but found no context") 101 | return 102 | } 103 | 104 | // TODO: make this can be customized. 105 | let transaction = Transaction(animation: .spring( 106 | response: 0.4, 107 | dampingFraction: 1, 108 | blendDuration: 0 109 | )) 110 | 111 | withTransaction(transaction) { 112 | 113 | if let value { 114 | let id = context.push( 115 | value: value, 116 | transition: transition, 117 | linkEnvironmentValues: linkEnvironments 118 | ) 119 | 120 | self.currentIdentifier = id 121 | return 122 | } 123 | 124 | if let destination { 125 | let id = context.push( 126 | destination: destination, 127 | transition: transition, 128 | linkEnvironmentValues: linkEnvironments 129 | ) 130 | 131 | self.currentIdentifier = id 132 | 133 | return 134 | } 135 | 136 | } 137 | 138 | } label: { 139 | label 140 | .modifier(transition.labelModifier()) 141 | .environment(\.stackedViewIdentifier, context?.stackedViews.first { $0.id == currentIdentifier }?.id) 142 | } 143 | .disabled(context == nil) 144 | 145 | } 146 | 147 | public func linkEnvironment( 148 | _ keyPath: WritableKeyPath, 149 | value: Value 150 | ) -> Self { 151 | var modified = self 152 | modified.linkEnvironments[keyPath: keyPath] = value 153 | return modified 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackLookupStragety.swift: -------------------------------------------------------------------------------- 1 | 2 | public struct StackLookupStragety { 3 | 4 | let `where`: (StackIdentifier) -> Bool 5 | 6 | public init(`where`: @escaping (StackIdentifier) -> Bool) { 7 | self.where = `where` 8 | } 9 | 10 | public static func identifiers(_ identifiers: Set) -> Self { 11 | self.init { i in 12 | identifiers.contains(i) 13 | } 14 | } 15 | 16 | public static func identifier(_ identifier: StackIdentifier) -> Self { 17 | self.init { i in 18 | i == identifier 19 | } 20 | } 21 | 22 | public static var current: Self { 23 | .init { _ in true } 24 | } 25 | 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackPath.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// ``SwiftUI/NavigationPath`` 4 | public struct StackPath: Equatable, CustomStringConvertible { 5 | 6 | /** 7 | The reason why it is class type object is can describe a path including the same value. 8 | */ 9 | public final class ItemBox: Hashable, Identifiable, CustomReflectable { 10 | 11 | public static func == (lhs: StackPath.ItemBox, rhs: StackPath.ItemBox) -> Bool { 12 | lhs === rhs 13 | } 14 | 15 | public func hash(into hasher: inout Hasher) { 16 | ObjectIdentifier(self).hash(into: &hasher) 17 | } 18 | 19 | public var id: ObjectIdentifier { 20 | .init(self) 21 | } 22 | 23 | public var stackedViewIdentifier: _StackedViewIdentifier { 24 | .init(id: id) 25 | } 26 | 27 | /// Returns actual value as `any Hashable`. 28 | /// This can cast into actual concrete type of value. 29 | public var value: any Hashable { 30 | storage.base as! any Hashable 31 | } 32 | 33 | public var subjectType: Any.Type { 34 | return type(of: value) 35 | } 36 | 37 | init(_ value: Value) { 38 | self.storage = .init(value) 39 | } 40 | 41 | // MARK: CustomReflectable 42 | 43 | public var customMirror: Mirror { 44 | .init( 45 | self, 46 | children: [ 47 | ("id", id), 48 | ("value", value), 49 | ], 50 | displayStyle: .struct, 51 | ancestorRepresentation: .suppressed 52 | ) 53 | } 54 | 55 | // MARK: - Private 56 | 57 | /// a type-erase value 58 | /// using AnyHashable to compatible with Equatable, Hashable 59 | private let storage: AnyHashable 60 | 61 | } 62 | 63 | public var count: Int { values.count } 64 | public var isEmpty: Bool { values.isEmpty } 65 | 66 | var values: [ItemBox] 67 | 68 | public init() { 69 | self.values = [] 70 | } 71 | 72 | public init(_ elements: S) where S: Sequence, S.Element: Hashable { 73 | self.values = elements.map { .init($0) } 74 | } 75 | 76 | mutating func append(itemBox: ItemBox) { 77 | values.append(itemBox) 78 | } 79 | 80 | public mutating func append(_ value: V) where V: Hashable { 81 | values.append(.init(value)) 82 | } 83 | 84 | public mutating func removeLast(_ k: Int = 1) { 85 | values.removeLast(k) 86 | } 87 | 88 | public var description: String { 89 | values.map { "\($0.value)" }.joined(separator: "\n-> ") 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackTransition+Matched.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import SwiftUISnapDraggingModifier 3 | import SwiftUISupport 4 | 5 | extension StackTransition where Self == StackTransitions.Matched { 6 | 7 | public static func matched(identifier: some Hashable, in namespace: Namespace.ID? = nil) -> Self { 8 | .init(identifier: identifier, in: namespace) 9 | } 10 | 11 | } 12 | 13 | extension StackTransitions { 14 | 15 | public struct Matched: StackTransition { 16 | 17 | private struct _LabelModifier: ViewModifier { 18 | 19 | /// available in Stack 20 | @Environment(\.stackNamespaceID) private var stackNamespaceID 21 | 22 | @Environment(\.stackLinkIsActive) private var isActive 23 | 24 | let specifiedNamespace: Namespace.ID? 25 | 26 | let identifier: AnyHashable 27 | 28 | private var usingNamespace: Namespace.ID? { 29 | specifiedNamespace ?? stackNamespaceID 30 | } 31 | 32 | func body(content: Content) -> some View { 33 | 34 | let base = Color.clear.hidden() 35 | .overlay( 36 | /// Content 37 | content 38 | // .frame(width: targetSize.width, height: targetSize.height, alignment: .center) 39 | // .modifier(ResizableModifier(isEnabled: true)) 40 | .opacity(isActive ? 0 : 1) 41 | // .blur(radius: isActive ? 10 : 0) 42 | ) 43 | 44 | // for unwind 45 | .matchedGeometryEffect( 46 | id: "movement".concat(identifier), 47 | in: usingNamespace!, 48 | properties: [.frame], 49 | isSource: false 50 | ) 51 | .matchedGeometryEffect( 52 | id: "mask".concat(identifier), 53 | in: usingNamespace!, 54 | properties: [], 55 | isSource: true 56 | ) 57 | // for matching frame 58 | .matchedGeometryEffect( 59 | id: "frame".concat(identifier), 60 | in: usingNamespace!, 61 | properties: [.frame], 62 | isSource: isActive == false 63 | ) 64 | 65 | ZStack { 66 | /// to make bounds 67 | /// actual content is displaying as overlay for center alignment in transition. 68 | content 69 | .hidden() 70 | .allowsHitTesting(false) 71 | 72 | base 73 | } 74 | 75 | } 76 | } 77 | 78 | private struct _DestinationModifier: ViewModifier { 79 | 80 | /// available in Stack 81 | @Environment(\.stackUnwindContext) var unwindContext 82 | 83 | /// available in Stack 84 | @Environment(\.stackNamespaceID) private var stackNamespaceID 85 | 86 | @State var appeared = false 87 | 88 | let specifiedNamespace: Namespace.ID? 89 | 90 | let identifier: AnyHashable 91 | 92 | @State var targetSize: CGSize = .zero 93 | 94 | private var usingNamespace: Namespace.ID? { 95 | specifiedNamespace ?? stackNamespaceID 96 | } 97 | 98 | func body(content: Content) -> some View { 99 | 100 | let base = ZStack(alignment: .top) { 101 | /// expandable shape to make the frame flexible for matched-geometry 102 | Color.clear.hidden().allowsHitTesting(false) 103 | 104 | /// Content 105 | content 106 | // to have constrained size if it's neutral sizing view. 107 | .frame(width: targetSize.width, height: targetSize.height) 108 | // .modifier(ResizableModifier(isEnabled: true)) 109 | // needs for unwind. give matchedGeometryEffect control for frame. 110 | .frame(minWidth: 0, minHeight: 0, alignment: .top) 111 | } 112 | // for backwards 113 | .matchedGeometryEffect( 114 | id: "movement".concat(identifier), 115 | in: usingNamespace!, 116 | properties: [], 117 | isSource: true 118 | ) 119 | .transition( 120 | AnyTransition.modifier( 121 | active: DestinationStyleModifier( 122 | opacity: 0, 123 | blurRadius: 0 124 | ), 125 | identity: DestinationStyleModifier( 126 | opacity: 1, 127 | blurRadius: 0 128 | ) 129 | ) 130 | ) 131 | // .blur(radius: appeared ? 0 : 10) 132 | .mask( 133 | RoundedRectangle( 134 | cornerRadius: appeared ? 0 : 8, 135 | style: .continuous 136 | ).fill(Color.black) 137 | ) 138 | .modifier( 139 | ContextualPopModifier() 140 | ) 141 | .matchedGeometryEffect( 142 | id: "mask".concat(identifier), 143 | in: usingNamespace!, 144 | properties: [.frame], 145 | isSource: false 146 | ) 147 | .matchedGeometryEffect( 148 | id: "frame".concat(identifier), 149 | in: usingNamespace!, 150 | properties: [.frame], 151 | isSource: true 152 | ) 153 | .measureSize($targetSize) 154 | 155 | .onAppear { 156 | withAnimation { 157 | appeared = true 158 | } 159 | } 160 | 161 | base 162 | 163 | } 164 | 165 | } 166 | 167 | public let identifier: AnyHashable 168 | public let specifiedNamespace: Namespace.ID? 169 | 170 | init(identifier: AnyHashable, in namespace: Namespace.ID?) { 171 | self.identifier = identifier 172 | self.specifiedNamespace = namespace 173 | } 174 | 175 | public func labelModifier() -> some ViewModifier { 176 | _LabelModifier(specifiedNamespace: specifiedNamespace, identifier: identifier) 177 | } 178 | 179 | public func destinationModifier(context: DestinationContext) -> some ViewModifier { 180 | _DestinationModifier(specifiedNamespace: specifiedNamespace, identifier: identifier) 181 | } 182 | 183 | } 184 | 185 | private struct DestinationStyleModifier: ViewModifier { 186 | 187 | public let opacity: Double 188 | public let blurRadius: Double 189 | 190 | public init( 191 | opacity: Double = 1, 192 | blurRadius: Double = 0 193 | ) { 194 | self.opacity = opacity 195 | self.blurRadius = blurRadius 196 | } 197 | 198 | func body(content: Content) -> some View { 199 | content 200 | .opacity(opacity) 201 | .blur(radius: blurRadius) 202 | } 203 | 204 | static var identity: Self { 205 | .init() 206 | } 207 | 208 | } 209 | } 210 | 211 | private struct ContextualPopModifier: ViewModifier { 212 | 213 | @Environment(\.stackUnwindContext) private var unwindContext 214 | 215 | @State var isTracking = false 216 | 217 | func body(content: Content) -> some View { 218 | content 219 | .mask( 220 | RoundedRectangle( 221 | cornerRadius: isTracking ? 8 : 0, 222 | style: .continuous 223 | ).fill(Color.black) 224 | ) 225 | .modifier( 226 | SnapDraggingModifier( 227 | activation: .init(minimumDistance: 20, regionToActivate: .screen), 228 | axis: [.horizontal, .vertical], 229 | springParameter: .interpolation(mass: 2, stiffness: 200, damping: 32), 230 | gestureMode: .highPriority, 231 | handler: .init( 232 | onStartDragging: { 233 | isTracking = true 234 | }, 235 | onEndDragging: { velocity, offset, contentSize in 236 | 237 | isTracking = false 238 | 239 | if abs(velocity.dx) > 50 || abs(offset.width) > (contentSize.width / 2) { 240 | Task { @MainActor in 241 | withAnimation( 242 | .interpolatingSpring(mass: 2, stiffness: 200, damping: 32) 243 | ) { 244 | unwindContext?.pop() 245 | } 246 | } 247 | return .zero 248 | } else { 249 | return .zero 250 | } 251 | }) 252 | ) 253 | ) 254 | 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackTransition+Slide.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import SwiftUISnapDraggingModifier 3 | import SwiftUISupport 4 | 5 | extension StackTransition where Self == StackTransitions.Slide { 6 | 7 | public static var slide: Self { 8 | .init() 9 | } 10 | 11 | } 12 | 13 | extension StackTransitions { 14 | 15 | public struct Slide: StackTransition { 16 | 17 | private struct _LabelModifier: ViewModifier { 18 | 19 | func body(content: Content) -> some View { 20 | content 21 | } 22 | } 23 | 24 | private struct _DestinationModifier: ViewModifier { 25 | 26 | let context: DestinationContext 27 | 28 | @Environment(\.stackNamespaceID) var stackNamespace 29 | 30 | /// available in Stack 31 | @Environment(\.stackUnwindContext) var unwindContext 32 | 33 | private func effectIdentifier() -> MatchedGeometryEffectIdentifiers.EdgeTrailing { 34 | switch context.backgroundContent { 35 | case .root: 36 | return .init(content: .root) 37 | case .stacked(let id): 38 | return .init(content: .stacked(id)) 39 | } 40 | } 41 | 42 | func body(content: Content) -> some View { 43 | 44 | content 45 | .matchedGeometryEffect( 46 | id: effectIdentifier(), 47 | in: stackNamespace!, 48 | properties: .frame, 49 | anchor: .leading, 50 | isSource: true 51 | ) 52 | .transition( 53 | .move(edge: .trailing).animation( 54 | .spring(response: 0.6, dampingFraction: 1, blendDuration: 0) 55 | ) 56 | ) 57 | .modifier( 58 | SnapDraggingModifier( 59 | activation: .init(minimumDistance: 20, regionToActivate: .edge(.leading)), 60 | axis: .horizontal, 61 | horizontalBoundary: .init(min: 0, max: .infinity, bandLength: 0), 62 | springParameter: .interpolation(mass: 1.0, stiffness: 500, damping: 500), 63 | gestureMode: .highPriority, 64 | handler: .init(onEndDragging: { velocity, offset, contentSize in 65 | 66 | if velocity.dx > 50 || offset.width > (contentSize.width / 2) { 67 | 68 | // waiting for animation to complete 69 | Task { @MainActor in 70 | try? await Task.sleep(nanoseconds: 280_000_000) 71 | unwindContext?.pop() 72 | } 73 | 74 | return .init(width: contentSize.width, height: 0) 75 | } else { 76 | return .zero 77 | } 78 | }) 79 | ) 80 | ) 81 | } 82 | } 83 | 84 | public func labelModifier() -> some ViewModifier { 85 | _LabelModifier() 86 | } 87 | 88 | public func destinationModifier(context: DestinationContext) -> some ViewModifier { 89 | _DestinationModifier(context: context) 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackTransition.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | public struct DestinationContext { 4 | 5 | public enum BackgroundContent { 6 | case root 7 | case stacked(_StackedViewIdentifier) 8 | } 9 | 10 | /// a content that currently displaying on top. 11 | public let backgroundContent: BackgroundContent 12 | 13 | } 14 | 15 | public protocol StackTransition { 16 | 17 | associatedtype LabelModifier: ViewModifier 18 | associatedtype DestinationModifier: ViewModifier 19 | 20 | func labelModifier() -> LabelModifier 21 | func destinationModifier(context: DestinationContext) -> DestinationModifier 22 | 23 | } 24 | 25 | extension StackTransition where Self == StackTransitions.Disabled { 26 | 27 | public static var disabled: Self { 28 | .init() 29 | } 30 | 31 | } 32 | 33 | extension StackTransition where Self == StackTransitions.Basic { 34 | 35 | public static func basic(transition: AnyTransition) -> Self { 36 | .init(transition: transition) 37 | } 38 | 39 | } 40 | 41 | 42 | public enum StackTransitions { 43 | } 44 | 45 | extension StackTransitions { 46 | 47 | public struct Disabled: StackTransition { 48 | 49 | private struct _Modifier: ViewModifier { 50 | func body(content: Content) -> some View { 51 | content 52 | } 53 | } 54 | 55 | public func labelModifier() -> some ViewModifier { 56 | _Modifier() 57 | } 58 | 59 | public func destinationModifier(context: DestinationContext) -> some ViewModifier { 60 | _Modifier() 61 | } 62 | 63 | } 64 | 65 | public struct Basic: StackTransition { 66 | 67 | private struct _LabelModifier: ViewModifier { 68 | func body(content: Content) -> some View { 69 | content 70 | } 71 | } 72 | 73 | private struct _DestinationModifier: ViewModifier { 74 | 75 | let transition: AnyTransition 76 | 77 | func body(content: Content) -> some View { 78 | content 79 | .transition(transition) 80 | } 81 | } 82 | 83 | public let transition: AnyTransition 84 | 85 | init(transition: AnyTransition) { 86 | self.transition = transition 87 | } 88 | 89 | public func labelModifier() -> some ViewModifier { 90 | _LabelModifier() 91 | } 92 | 93 | public func destinationModifier(context: DestinationContext) -> some ViewModifier { 94 | _DestinationModifier(transition: transition) 95 | } 96 | 97 | } 98 | 99 | } 100 | 101 | private struct _StackLinkIsActive: EnvironmentKey { 102 | 103 | static var defaultValue: Bool { 104 | return false 105 | } 106 | 107 | } 108 | 109 | private struct _StackedViewIdentifierKey: EnvironmentKey { 110 | 111 | static var defaultValue: _StackedViewIdentifier? { 112 | return nil 113 | } 114 | 115 | } 116 | 117 | extension EnvironmentValues { 118 | 119 | public var stackLinkIsActive: Bool { 120 | stackedViewIdentifier != nil 121 | } 122 | 123 | } 124 | 125 | 126 | extension EnvironmentValues { 127 | 128 | public var stackedViewIdentifier: _StackedViewIdentifier? { 129 | get { self[_StackedViewIdentifierKey.self] } 130 | set { self[_StackedViewIdentifierKey.self] = newValue } 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackUnwindLink.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /** 4 | A view that controls a stack presentation. 5 | 6 | Users click or tap a unwind link to pop the current displaying view inside a ``AbstractStack``. 7 | */ 8 | public struct StackUnwindLink: View { 9 | 10 | /// The option for which ``StackUnwindContext`` should be used. 11 | public enum Target { 12 | /// Uses nearest stack's context 13 | case automatic 14 | case specific(StackUnwindContext?) 15 | } 16 | 17 | public enum UnwindMode { 18 | /// pop one 19 | case one 20 | /// pop to root 21 | case all 22 | } 23 | 24 | /// It appears if this view is in ``AbstractStack``. 25 | @Environment(\.stackUnwindContext) private var automaticUnwindContext 26 | 27 | public let target: Target 28 | public let mode: UnwindMode 29 | 30 | private let label: Label 31 | private let animation: Animation 32 | 33 | public init( 34 | target: Target = .automatic, 35 | mode: UnwindMode = .one, 36 | animation: Animation = .spring( 37 | response: 0.4, 38 | dampingFraction: 1, 39 | blendDuration: 0 40 | ), 41 | @ViewBuilder label: () -> Label 42 | ) { 43 | self.target = target 44 | self.mode = mode 45 | self.animation = animation 46 | self.label = label() 47 | } 48 | 49 | public var body: some View { 50 | Button { 51 | 52 | var targetUnwindContext: StackUnwindContext? { 53 | switch target { 54 | case .automatic: 55 | return self.automaticUnwindContext 56 | case .specific(let unwindContext): 57 | return unwindContext 58 | } 59 | } 60 | 61 | guard let targetUnwindContext else { 62 | // TODO: assertion 63 | return 64 | } 65 | 66 | switch mode { 67 | case .all: 68 | // FIXME: how to run animation, inheriting specified transition 69 | withAnimation(animation) { 70 | targetUnwindContext.popAll() 71 | } 72 | case .one: 73 | // FIXME: how to run animation, inheriting specified transition 74 | withAnimation(animation) { 75 | targetUnwindContext.pop() 76 | } 77 | } 78 | 79 | 80 | } label: { 81 | label 82 | } 83 | .disabled(automaticUnwindContext == nil) 84 | 85 | } 86 | } 87 | 88 | /** 89 | A context for unwind in a ``AbstractStack`` 90 | */ 91 | @MainActor 92 | public struct StackUnwindContext { 93 | 94 | private let stackContext: _StackContext 95 | private let stackIdentifier: _StackedViewIdentifier 96 | 97 | nonisolated init(stackContext: _StackContext, stackIdentifier: _StackedViewIdentifier) { 98 | self.stackContext = stackContext 99 | self.stackIdentifier = stackIdentifier 100 | } 101 | 102 | public func pop() { 103 | stackContext.pop(identifier: stackIdentifier) 104 | } 105 | 106 | public func popAll() { 107 | stackContext.popAll() 108 | } 109 | 110 | } 111 | 112 | extension EnvironmentValues { 113 | 114 | /** 115 | A context for unwind in a ``AbstractStack`` 116 | */ 117 | public var stackUnwindContext: StackUnwindContext? { 118 | guard let stackContext, let stackIdentifier else { return nil } 119 | return .init(stackContext: stackContext, stackIdentifier: stackIdentifier) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/StackedView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | /// A wrapper view that displays content with identifier which uses on Pop operation. 4 | public struct StackedView: View, Identifiable, Equatable { 5 | 6 | /// a material of how this view is stacked. 7 | public enum Material { 8 | /// For dynamic destination according to the value. 9 | case value(StackPath.ItemBox) 10 | /// For dynamic destination according to the binding 11 | case moment(Binding) 12 | /// For static destination - Link has a destination in the declaration 13 | case volatile 14 | } 15 | 16 | public static func == (lhs: StackedView, rhs: StackedView) -> Bool { 17 | lhs.id == rhs.id 18 | } 19 | 20 | public let id: _StackedViewIdentifier 21 | 22 | private let content: AnyView 23 | 24 | public let material: Material 25 | public let linkEnvironmentValues: LinkEnvironmentValues 26 | 27 | @Environment(\.stackNamespaceID) var stackNamespace 28 | 29 | init( 30 | material: Material, 31 | identifier: _StackedViewIdentifier, 32 | linkEnvironmentValues: LinkEnvironmentValues, 33 | content: some View 34 | ) { 35 | self.material = material 36 | self.id = identifier 37 | self.linkEnvironmentValues = linkEnvironmentValues 38 | self.content = .init(content) 39 | } 40 | 41 | public var body: some View { 42 | 43 | content 44 | .matchedGeometryEffect( 45 | id: MatchedGeometryEffectIdentifiers.EdgeTrailing(content: .stacked(id)), 46 | in: stackNamespace!, 47 | anchor: .trailing, 48 | isSource: false 49 | ) 50 | .environment(\.stackIdentifier, id) 51 | .onAppear { 52 | 53 | } 54 | .onDisappear { 55 | 56 | } 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/View+stackDestination.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import Combine 3 | 4 | // MARK: - View extensions 5 | 6 | extension View { 7 | 8 | public func stackDestination( 9 | for data: D.Type, 10 | target: StackLookupStragety = .current, 11 | @ViewBuilder destination: @escaping (D) -> C 12 | ) -> some View where D: Hashable, C: View { 13 | 14 | self.modifier( 15 | StackEnvironmentModifier( 16 | withValue: { context in 17 | guard let context else { 18 | return 19 | } 20 | context.registerDestination(for: data.self, target: target, destination: destination) 21 | } 22 | ) 23 | ) 24 | 25 | } 26 | 27 | public func stackDestination( 28 | isPresented: Binding, 29 | target: StackLookupStragety = .current, 30 | @ViewBuilder destination: @escaping () -> V 31 | ) -> some View where V: View { 32 | 33 | self.modifier( 34 | StackMomentaryPushModifier( 35 | isPresented: isPresented, 36 | destination: destination, 37 | target: target 38 | ) 39 | ) 40 | 41 | } 42 | 43 | } 44 | 45 | private struct StackEnvironmentModifier: ViewModifier { 46 | 47 | @Environment(\.stackContext) private var context 48 | 49 | private let _withValue: @MainActor (_StackContext?) -> Void 50 | 51 | init(withValue: @escaping @MainActor (_StackContext?) -> Void) { 52 | self._withValue = withValue 53 | } 54 | 55 | func body(content: Content) -> some View { 56 | 57 | // needs for restoreing path in this timing. 58 | _withValue(context) 59 | 60 | return 61 | content 62 | .onAppear { 63 | // keep to activate modifier. 64 | } 65 | .onDisappear { 66 | } 67 | } 68 | } 69 | 70 | private struct StackMomentaryPushModifier: ViewModifier { 71 | 72 | @Environment(\.stackContext) private var context 73 | 74 | @Binding var isPresented: Bool 75 | 76 | @State var currentIdentifier: _StackedViewIdentifier? 77 | 78 | let destination: () -> Destination 79 | 80 | let target: StackLookupStragety 81 | 82 | func body(content: Content) -> some View { 83 | 84 | content 85 | .onChangeWithPrevious( 86 | of: isPresented, 87 | emitsInitial: true, 88 | perform: { isPresented, _ in 89 | 90 | guard let context = context?.lookup(strategy: target) else { 91 | return 92 | } 93 | 94 | if isPresented { 95 | // FIXME: LinkEnvironmentValues 96 | currentIdentifier = context.push( 97 | binding: $isPresented, 98 | destination: destination(), 99 | linkEnvironmentValues: .init() 100 | ) 101 | } else { 102 | 103 | if let currentIdentifier { 104 | self.currentIdentifier = nil 105 | context.pop(identifier: currentIdentifier) 106 | } 107 | 108 | } 109 | 110 | } 111 | ) 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Sources/SwiftUIStack/_StackContext.swift: -------------------------------------------------------------------------------- 1 | import Combine 2 | import SwiftUI 3 | 4 | enum StackingViewNode { 5 | case value(StackedView, AnyHashable) 6 | case moment(StackedView) 7 | } 8 | 9 | struct TypeKey: Hashable { 10 | 11 | let base: String 12 | 13 | init(_ base: T.Type) { 14 | self.base = String(reflecting: base) 15 | } 16 | 17 | init(any base: Any.Type) { 18 | self.base = String(reflecting: base) 19 | } 20 | } 21 | 22 | @_spi(StackContext) 23 | @MainActor 24 | public final class _StackContext: ObservableObject, Equatable { 25 | 26 | private struct Destination { 27 | 28 | let target: StackLookupStragety 29 | let _view: (StackPath.ItemBox) -> AnyView 30 | 31 | init(target: StackLookupStragety, view: @escaping (StackPath.ItemBox) -> AnyView) { 32 | self.target = target 33 | self._view = view 34 | } 35 | 36 | func make(item: StackPath.ItemBox) -> AnyView { 37 | _view(item) 38 | } 39 | 40 | } 41 | 42 | nonisolated public static func == (lhs: _StackContext, rhs: _StackContext) -> Bool { 43 | lhs === rhs 44 | } 45 | 46 | @Published private(set) var stackedViews: [StackedView] = [] 47 | 48 | @Published var path: StackPath = .init() 49 | 50 | /// Functions that creates a view associated with type of value. 51 | private var destinationTable: [TypeKey: Destination] = [:] 52 | 53 | /// the parent context 54 | private weak var parent: _StackContext? 55 | let identifier: StackIdentifier 56 | 57 | init( 58 | identifier: StackIdentifier? 59 | ) { 60 | self.identifier = identifier ?? .init("unnamed") 61 | Log.debug(.stack, "Init \(self)") 62 | } 63 | 64 | /// Makes a relationship to parent. 65 | func set(parent: _StackContext?) { 66 | self.parent = parent 67 | } 68 | 69 | /** 70 | Updates current stacked views with given path - Restoring state 71 | */ 72 | func receivePathUpdates(path: StackPath) { 73 | 74 | let views = path.values 75 | .map { 76 | makeStackedView(itemBox: $0, transition: .disabled, linkEnvironmentValues: .init())?.0 77 | } 78 | .compactMap { $0 } 79 | 80 | self.stackedViews = views 81 | self.path = path 82 | 83 | } 84 | 85 | func registerDestination( 86 | for data: D.Type, 87 | target: StackLookupStragety, 88 | destination: @escaping (D) -> Destination 89 | ) { 90 | 91 | let key = TypeKey(D.self) 92 | 93 | guard destinationTable[key] == nil else { 94 | // Log.debug( 95 | // .stack, 96 | // "The destination for \(D.self) is already registered. Currently restricted in overriding." 97 | // ) 98 | return 99 | } 100 | 101 | destinationTable[key] = .init( 102 | target: target, 103 | view: { itemBox in 104 | AnyView(destination(itemBox.value as! D)) 105 | } 106 | ) 107 | 108 | } 109 | 110 | private func makeStackedView( 111 | itemBox: StackPath.ItemBox, 112 | transition: some StackTransition, 113 | linkEnvironmentValues: LinkEnvironmentValues 114 | ) -> (StackedView, StackLookupStragety)? { 115 | 116 | let key = TypeKey(any: itemBox.subjectType) 117 | 118 | guard let destination = destinationTable[key] else { 119 | Log.error( 120 | .stack, 121 | """ 122 | ❌ Failed to push - Stack could not found a destination for value \(itemBox) from \(key). 123 | Make sure `stackDestination` methods are inside of stack. It won't work if using that from stack like `Stack { ... }.stackDestination`. 124 | """ 125 | ) 126 | return nil 127 | } 128 | 129 | stackedViews.last?.id 130 | 131 | let stackedView = StackedView( 132 | material: .value(itemBox), 133 | identifier: itemBox.stackedViewIdentifier, 134 | linkEnvironmentValues: linkEnvironmentValues, 135 | content: destination.make(item: itemBox) 136 | .modifier( 137 | RestoreSafeAreaModifier() 138 | .concat( 139 | transition.destinationModifier(context: makeDestinationContext()) 140 | ) 141 | ) 142 | ) 143 | 144 | return (stackedView, destination.target) 145 | } 146 | 147 | private func makeDestinationContext() -> DestinationContext { 148 | if let id = stackedViews.last?.id { 149 | return .init(backgroundContent: .stacked(id)) 150 | } 151 | return .init(backgroundContent: .root) 152 | } 153 | 154 | /** 155 | For value-push 156 | Returns nil if push was failed 157 | */ 158 | @discardableResult 159 | func push( 160 | value: Value, 161 | transition: some StackTransition, 162 | linkEnvironmentValues: LinkEnvironmentValues 163 | ) -> _StackedViewIdentifier? { 164 | 165 | func _push(itemBox: StackPath.ItemBox) -> StackPath.ItemBox? { 166 | 167 | guard 168 | let view = makeStackedView( 169 | itemBox: itemBox, 170 | transition: transition, 171 | linkEnvironmentValues: linkEnvironmentValues 172 | )?.0 173 | else { 174 | // failed to push 175 | return nil 176 | } 177 | 178 | stackedViews.append(view) 179 | 180 | return itemBox 181 | } 182 | 183 | let proposedItemBox = StackPath.ItemBox(value) 184 | 185 | guard let itemBox = _push(itemBox: proposedItemBox) else { 186 | return nil 187 | } 188 | // FIXME: Use linkEnvironmentValues 189 | path.append(itemBox: itemBox) 190 | return itemBox.stackedViewIdentifier 191 | } 192 | 193 | /* 194 | From StackLink, associated with destination 195 | */ 196 | @discardableResult 197 | func push( 198 | destination: some View, 199 | transition: some StackTransition, 200 | linkEnvironmentValues: LinkEnvironmentValues 201 | ) -> _StackedViewIdentifier { 202 | // TODO: how to validate the desination is already presented 203 | 204 | // FIXME: Use linkEnvironmentValues 205 | 206 | let identifier = _StackedViewIdentifier(id: UUID().uuidString) 207 | 208 | let stackedView = StackedView( 209 | material: .volatile, 210 | identifier: identifier, 211 | linkEnvironmentValues: linkEnvironmentValues, 212 | content: 213 | destination 214 | .modifier( 215 | RestoreSafeAreaModifier() 216 | .concat( 217 | transition.destinationModifier(context: makeDestinationContext()) 218 | ) 219 | ) 220 | ) 221 | 222 | stackedViews.append(stackedView) 223 | 224 | return identifier 225 | } 226 | 227 | /** 228 | For momentary-push 229 | */ 230 | func push( 231 | binding: Binding, 232 | destination: some View, 233 | linkEnvironmentValues: LinkEnvironmentValues 234 | ) -> _StackedViewIdentifier { 235 | 236 | // FIXME: Use linkEnvironmentValues 237 | 238 | let identifier = _StackedViewIdentifier(id: UUID().uuidString) 239 | 240 | let stackedView = StackedView( 241 | material: .moment(binding), 242 | identifier: identifier, 243 | linkEnvironmentValues: linkEnvironmentValues, 244 | content: destination 245 | ) 246 | 247 | stackedViews.append(stackedView) 248 | 249 | return identifier 250 | } 251 | 252 | func lookup(strategy: StackLookupStragety) -> _StackContext? { 253 | 254 | if strategy.where(identifier) { 255 | return self 256 | } else { 257 | return parent?.lookup(strategy: strategy) 258 | } 259 | 260 | } 261 | 262 | public func popAll() { 263 | 264 | stackedViews.removeAll { e in 265 | switch e.material { 266 | case .value: 267 | break 268 | case .moment(let binding): 269 | // turn off is-presenting binding 270 | binding.wrappedValue = false 271 | case .volatile: 272 | break 273 | } 274 | return true 275 | } 276 | 277 | path = .init() 278 | } 279 | 280 | /** 281 | Pops a view associated with given identifier. 282 | Turns off the flag of presenting if its Binding presents. 283 | */ 284 | public func pop(identifier: _StackedViewIdentifier) { 285 | 286 | stackedViews.removeAll( 287 | after: { e in 288 | e.id == identifier 289 | }, 290 | perform: { e in 291 | 292 | Log.debug(.stack, "Pop => \(e)") 293 | 294 | switch e.material { 295 | case .value: 296 | break 297 | case .moment(let binding): 298 | 299 | // turn off is-presenting binding 300 | binding.wrappedValue = false 301 | 302 | case .volatile: 303 | break 304 | } 305 | } 306 | ) 307 | 308 | let newPath = stackedViews.reduce(into: StackPath()) { partialResult, view in 309 | 310 | switch view.material { 311 | case .value(let itemBox): 312 | partialResult.append(itemBox: itemBox) 313 | case .moment: 314 | break 315 | case .volatile: 316 | break 317 | } 318 | 319 | } 320 | 321 | path = newPath 322 | 323 | } 324 | 325 | deinit { 326 | Log.debug(.stack, "Deinit \(self)") 327 | } 328 | } 329 | 330 | public struct _StackedViewIdentifier: Hashable { 331 | 332 | enum Identifier: Hashable { 333 | case objectIdentifier(ObjectIdentifier) 334 | case string(String) 335 | } 336 | 337 | let id: Identifier 338 | 339 | init( 340 | id: ObjectIdentifier 341 | ) { 342 | self.id = .objectIdentifier(id) 343 | } 344 | 345 | init( 346 | id: String 347 | ) { 348 | self.id = .string(id) 349 | } 350 | 351 | } 352 | 353 | private enum _StackNamespaceIDKey: EnvironmentKey { 354 | static var defaultValue: Namespace.ID? { nil } 355 | } 356 | 357 | private enum _StackedViewNamespaceIDKey: EnvironmentKey { 358 | static var defaultValue: Namespace.ID? { nil } 359 | } 360 | 361 | private enum _StackContextKey: EnvironmentKey { 362 | static var defaultValue: _StackContext? { nil } 363 | } 364 | 365 | private enum _StackFragmentKey: EnvironmentKey { 366 | static var defaultValue: _StackedViewIdentifier? { nil } 367 | } 368 | 369 | extension EnvironmentValues { 370 | 371 | @_spi(StackContext) 372 | public var stackContext: _StackContext? { 373 | get { self[_StackContextKey.self] } 374 | set { self[_StackContextKey.self] = newValue } 375 | } 376 | 377 | /// A namespace provided by stack 378 | @_spi(Internal) 379 | public var stackNamespaceID: Namespace.ID? { 380 | get { self[_StackNamespaceIDKey.self] } 381 | set { self[_StackNamespaceIDKey.self] = newValue } 382 | } 383 | 384 | /// An identifier for stacked view. 385 | var stackIdentifier: _StackedViewIdentifier? { 386 | get { self[_StackFragmentKey.self] } 387 | set { self[_StackFragmentKey.self] = newValue } 388 | } 389 | } 390 | 391 | extension Array { 392 | 393 | mutating func removeAll(after filterClosure: (Element) -> Bool, perform: (Element) -> Void) { 394 | 395 | var found = false 396 | 397 | removeAll { e in 398 | 399 | if found { 400 | perform(e) 401 | return true 402 | } 403 | 404 | let _found = filterClosure(e) 405 | 406 | if _found { 407 | found = true 408 | perform(e) 409 | return true 410 | } else { 411 | return false 412 | } 413 | 414 | } 415 | 416 | } 417 | 418 | } 419 | -------------------------------------------------------------------------------- /Stack.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Stack.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Stack.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "swiftui-color", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/FluidGroup/swiftui-color", 7 | "state" : { 8 | "revision" : "c55af612894b03c876f4fc1601e7c1afb843bcd8", 9 | "version" : "1.0.0" 10 | } 11 | }, 12 | { 13 | "identity" : "swiftui-gesture-velocity", 14 | "kind" : "remoteSourceControl", 15 | "location" : "https://github.com/FluidGroup/swiftui-gesture-velocity", 16 | "state" : { 17 | "revision" : "9c83f8995f9e5efc29db2fca4b9ff058283f1603", 18 | "version" : "1.0.0" 19 | } 20 | }, 21 | { 22 | "identity" : "viewinspector", 23 | "kind" : "remoteSourceControl", 24 | "location" : "https://github.com/nalexn/ViewInspector.git", 25 | "state" : { 26 | "revision" : "4effbd9143ab797eb60d2f32d4265c844c980946", 27 | "version" : "0.9.5" 28 | } 29 | } 30 | ], 31 | "version" : 2 32 | } 33 | -------------------------------------------------------------------------------- /Stack.xcworkspace/xcshareddata/xcschemes/Stack.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 42 | 43 | 49 | 50 | 56 | 57 | 58 | 59 | 61 | 62 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /StackApp/Stack.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 56; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4B15FAB829FFED8A000442FA /* BookMatchedShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B15FAB729FFED89000442FA /* BookMatchedShape.swift */; }; 11 | 4B29A6FD29FC5C31003CCC00 /* BookFullScreenStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B29A6FC29FC5C31003CCC00 /* BookFullScreenStack.swift */; }; 12 | 4B29A6FF29FC5CA1003CCC00 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B29A6FE29FC5CA1003CCC00 /* Colors.swift */; }; 13 | 4B2A923C28E4B6F9006624AD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2A923B28E4B6F9006624AD /* AppDelegate.swift */; }; 14 | 4B2A923E28E4B6F9006624AD /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2A923D28E4B6F9006624AD /* ContentView.swift */; }; 15 | 4B2A924028E4B6FA006624AD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B2A923F28E4B6FA006624AD /* Assets.xcassets */; }; 16 | 4B2A924328E4B6FA006624AD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B2A924228E4B6FA006624AD /* Preview Assets.xcassets */; }; 17 | 4B2A924D28E4B6FA006624AD /* StackDemoAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2A924C28E4B6FA006624AD /* StackDemoAppTests.swift */; }; 18 | 4B2A925728E4B6FA006624AD /* StackDemoAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2A925628E4B6FA006624AD /* StackDemoAppUITests.swift */; }; 19 | 4B2A925928E4B6FA006624AD /* StackDemoAppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2A925828E4B6FA006624AD /* StackDemoAppUITestsLaunchTests.swift */; }; 20 | 4B51F641290ACAAE0015CC21 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B51F640290ACAAE0015CC21 /* Launch Screen.storyboard */; }; 21 | 4B6D472329FC2A5900658A0F /* swiftui-color in Frameworks */ = {isa = PBXBuildFile; productRef = 4B6D472229FC2A5900658A0F /* swiftui-color */; }; 22 | 4B77AA5B28E4BE75006307DA /* BookStackNoPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B77AA5A28E4BE75006307DA /* BookStackNoPath.swift */; }; 23 | 4B77AA5D28E4BEA2006307DA /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B77AA5C28E4BEA2006307DA /* Model.swift */; }; 24 | 4B77AA5F28E4BF0C006307DA /* Views.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B77AA5E28E4BF0C006307DA /* Views.swift */; }; 25 | 4B77AA6128E4D1F9006307DA /* BookNesting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B77AA6028E4D1F9006307DA /* BookNesting.swift */; }; 26 | 4B77AA6328E54FE9006307DA /* BookNavigationStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B77AA6228E54FE9006307DA /* BookNavigationStack.swift */; }; 27 | 4BC315B42A09423600D86A6C /* SwiftUIStack in Frameworks */ = {isa = PBXBuildFile; productRef = 4BC315B32A09423600D86A6C /* SwiftUIStack */; }; 28 | 4BC6C24B28E4B8120081E217 /* BookStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC6C24A28E4B8120081E217 /* BookStack.swift */; }; 29 | 4BC6C24D28E4B83B0081E217 /* StatefulPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC6C24C28E4B83B0081E217 /* StatefulPage.swift */; }; 30 | 4BCFDBE7290FC271004D58D3 /* BookStack_Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BCFDBE6290FC271004D58D3 /* BookStack_Grid.swift */; }; 31 | 4BDA70642A0382F5001AC9AF /* IGTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDA70632A0382F5001AC9AF /* IGTabView.swift */; }; 32 | 4BDA70662A0382FE001AC9AF /* IGAppRoot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDA70652A0382FE001AC9AF /* IGAppRoot.swift */; }; 33 | /* End PBXBuildFile section */ 34 | 35 | /* Begin PBXContainerItemProxy section */ 36 | 4B2A924928E4B6FA006624AD /* PBXContainerItemProxy */ = { 37 | isa = PBXContainerItemProxy; 38 | containerPortal = 4B2A91FF28E4B627006624AD /* Project object */; 39 | proxyType = 1; 40 | remoteGlobalIDString = 4B2A923828E4B6F9006624AD; 41 | remoteInfo = StackDemoApp; 42 | }; 43 | 4B2A925328E4B6FA006624AD /* PBXContainerItemProxy */ = { 44 | isa = PBXContainerItemProxy; 45 | containerPortal = 4B2A91FF28E4B627006624AD /* Project object */; 46 | proxyType = 1; 47 | remoteGlobalIDString = 4B2A923828E4B6F9006624AD; 48 | remoteInfo = StackDemoApp; 49 | }; 50 | /* End PBXContainerItemProxy section */ 51 | 52 | /* Begin PBXFileReference section */ 53 | 4B15FAB729FFED89000442FA /* BookMatchedShape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookMatchedShape.swift; sourceTree = ""; }; 54 | 4B29A6FC29FC5C31003CCC00 /* BookFullScreenStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookFullScreenStack.swift; sourceTree = ""; }; 55 | 4B29A6FE29FC5CA1003CCC00 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; 56 | 4B2A923428E4B664006624AD /* swiftui-stack */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "swiftui-stack"; path = ..; sourceTree = ""; }; 57 | 4B2A923928E4B6F9006624AD /* StackDemoApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StackDemoApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | 4B2A923B28E4B6F9006624AD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 59 | 4B2A923D28E4B6F9006624AD /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 60 | 4B2A923F28E4B6FA006624AD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 61 | 4B2A924228E4B6FA006624AD /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 62 | 4B2A924828E4B6FA006624AD /* StackDemoAppTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StackDemoAppTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 63 | 4B2A924C28E4B6FA006624AD /* StackDemoAppTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackDemoAppTests.swift; sourceTree = ""; }; 64 | 4B2A925228E4B6FA006624AD /* StackDemoAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StackDemoAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 65 | 4B2A925628E4B6FA006624AD /* StackDemoAppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackDemoAppUITests.swift; sourceTree = ""; }; 66 | 4B2A925828E4B6FA006624AD /* StackDemoAppUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackDemoAppUITestsLaunchTests.swift; sourceTree = ""; }; 67 | 4B51F640290ACAAE0015CC21 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; }; 68 | 4B554D5D2A06D29A00DA1BF2 /* swiftui-snap-dragging-modifier */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "swiftui-snap-dragging-modifier"; path = "../submodules/swiftui-snap-dragging-modifier"; sourceTree = ""; }; 69 | 4B77AA5A28E4BE75006307DA /* BookStackNoPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookStackNoPath.swift; sourceTree = ""; }; 70 | 4B77AA5C28E4BEA2006307DA /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; 71 | 4B77AA5E28E4BF0C006307DA /* Views.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Views.swift; sourceTree = ""; }; 72 | 4B77AA6028E4D1F9006307DA /* BookNesting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookNesting.swift; sourceTree = ""; }; 73 | 4B77AA6228E54FE9006307DA /* BookNavigationStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookNavigationStack.swift; sourceTree = ""; }; 74 | 4B92D47E2A0267D80053760B /* swiftui-support */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "swiftui-support"; path = "../submodules/swiftui-support"; sourceTree = ""; }; 75 | 4BC6C24A28E4B8120081E217 /* BookStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookStack.swift; sourceTree = ""; }; 76 | 4BC6C24C28E4B83B0081E217 /* StatefulPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatefulPage.swift; sourceTree = ""; }; 77 | 4BCFDBE6290FC271004D58D3 /* BookStack_Grid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookStack_Grid.swift; sourceTree = ""; }; 78 | 4BDA70632A0382F5001AC9AF /* IGTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IGTabView.swift; sourceTree = ""; }; 79 | 4BDA70652A0382FE001AC9AF /* IGAppRoot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IGAppRoot.swift; sourceTree = ""; }; 80 | /* End PBXFileReference section */ 81 | 82 | /* Begin PBXFrameworksBuildPhase section */ 83 | 4B2A923628E4B6F9006624AD /* Frameworks */ = { 84 | isa = PBXFrameworksBuildPhase; 85 | buildActionMask = 2147483647; 86 | files = ( 87 | 4B6D472329FC2A5900658A0F /* swiftui-color in Frameworks */, 88 | 4BC315B42A09423600D86A6C /* SwiftUIStack in Frameworks */, 89 | ); 90 | runOnlyForDeploymentPostprocessing = 0; 91 | }; 92 | 4B2A924528E4B6FA006624AD /* Frameworks */ = { 93 | isa = PBXFrameworksBuildPhase; 94 | buildActionMask = 2147483647; 95 | files = ( 96 | ); 97 | runOnlyForDeploymentPostprocessing = 0; 98 | }; 99 | 4B2A924F28E4B6FA006624AD /* Frameworks */ = { 100 | isa = PBXFrameworksBuildPhase; 101 | buildActionMask = 2147483647; 102 | files = ( 103 | ); 104 | runOnlyForDeploymentPostprocessing = 0; 105 | }; 106 | /* End PBXFrameworksBuildPhase section */ 107 | 108 | /* Begin PBXGroup section */ 109 | 4B2A91FE28E4B627006624AD = { 110 | isa = PBXGroup; 111 | children = ( 112 | 4B554D5D2A06D29A00DA1BF2 /* swiftui-snap-dragging-modifier */, 113 | 4B92D47E2A0267D80053760B /* swiftui-support */, 114 | 4B2A923428E4B664006624AD /* swiftui-stack */, 115 | 4B2A923A28E4B6F9006624AD /* StackDemoApp */, 116 | 4B2A924B28E4B6FA006624AD /* StackDemoAppTests */, 117 | 4B2A925528E4B6FA006624AD /* StackDemoAppUITests */, 118 | 4B2A920828E4B627006624AD /* Products */, 119 | 4BC6C24728E4B7490081E217 /* Frameworks */, 120 | ); 121 | sourceTree = ""; 122 | }; 123 | 4B2A920828E4B627006624AD /* Products */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 4B2A923928E4B6F9006624AD /* StackDemoApp.app */, 127 | 4B2A924828E4B6FA006624AD /* StackDemoAppTests.xctest */, 128 | 4B2A925228E4B6FA006624AD /* StackDemoAppUITests.xctest */, 129 | ); 130 | name = Products; 131 | sourceTree = ""; 132 | }; 133 | 4B2A923A28E4B6F9006624AD /* StackDemoApp */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 4BDA70622A0382D3001AC9AF /* Instagram */, 137 | 4B15FAB729FFED89000442FA /* BookMatchedShape.swift */, 138 | 4B29A6FC29FC5C31003CCC00 /* BookFullScreenStack.swift */, 139 | 4B2A923B28E4B6F9006624AD /* AppDelegate.swift */, 140 | 4B2A923D28E4B6F9006624AD /* ContentView.swift */, 141 | 4BC6C24A28E4B8120081E217 /* BookStack.swift */, 142 | 4BCFDBE6290FC271004D58D3 /* BookStack_Grid.swift */, 143 | 4B77AA5A28E4BE75006307DA /* BookStackNoPath.swift */, 144 | 4B77AA6228E54FE9006307DA /* BookNavigationStack.swift */, 145 | 4B2A923F28E4B6FA006624AD /* Assets.xcassets */, 146 | 4B2A924128E4B6FA006624AD /* Preview Content */, 147 | 4BC6C24C28E4B83B0081E217 /* StatefulPage.swift */, 148 | 4B77AA5C28E4BEA2006307DA /* Model.swift */, 149 | 4B77AA5E28E4BF0C006307DA /* Views.swift */, 150 | 4B77AA6028E4D1F9006307DA /* BookNesting.swift */, 151 | 4B51F640290ACAAE0015CC21 /* Launch Screen.storyboard */, 152 | 4B29A6FE29FC5CA1003CCC00 /* Colors.swift */, 153 | ); 154 | path = StackDemoApp; 155 | sourceTree = ""; 156 | }; 157 | 4B2A924128E4B6FA006624AD /* Preview Content */ = { 158 | isa = PBXGroup; 159 | children = ( 160 | 4B2A924228E4B6FA006624AD /* Preview Assets.xcassets */, 161 | ); 162 | path = "Preview Content"; 163 | sourceTree = ""; 164 | }; 165 | 4B2A924B28E4B6FA006624AD /* StackDemoAppTests */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 4B2A924C28E4B6FA006624AD /* StackDemoAppTests.swift */, 169 | ); 170 | path = StackDemoAppTests; 171 | sourceTree = ""; 172 | }; 173 | 4B2A925528E4B6FA006624AD /* StackDemoAppUITests */ = { 174 | isa = PBXGroup; 175 | children = ( 176 | 4B2A925628E4B6FA006624AD /* StackDemoAppUITests.swift */, 177 | 4B2A925828E4B6FA006624AD /* StackDemoAppUITestsLaunchTests.swift */, 178 | ); 179 | path = StackDemoAppUITests; 180 | sourceTree = ""; 181 | }; 182 | 4BC6C24728E4B7490081E217 /* Frameworks */ = { 183 | isa = PBXGroup; 184 | children = ( 185 | ); 186 | name = Frameworks; 187 | sourceTree = ""; 188 | }; 189 | 4BDA70622A0382D3001AC9AF /* Instagram */ = { 190 | isa = PBXGroup; 191 | children = ( 192 | 4BDA70652A0382FE001AC9AF /* IGAppRoot.swift */, 193 | 4BDA70632A0382F5001AC9AF /* IGTabView.swift */, 194 | ); 195 | path = Instagram; 196 | sourceTree = ""; 197 | }; 198 | /* End PBXGroup section */ 199 | 200 | /* Begin PBXNativeTarget section */ 201 | 4B2A923828E4B6F9006624AD /* StackDemoApp */ = { 202 | isa = PBXNativeTarget; 203 | buildConfigurationList = 4B2A925A28E4B6FA006624AD /* Build configuration list for PBXNativeTarget "StackDemoApp" */; 204 | buildPhases = ( 205 | 4B2A923528E4B6F9006624AD /* Sources */, 206 | 4B2A923628E4B6F9006624AD /* Frameworks */, 207 | 4B2A923728E4B6F9006624AD /* Resources */, 208 | ); 209 | buildRules = ( 210 | ); 211 | dependencies = ( 212 | ); 213 | name = StackDemoApp; 214 | packageProductDependencies = ( 215 | 4B6D472229FC2A5900658A0F /* swiftui-color */, 216 | 4BC315B32A09423600D86A6C /* SwiftUIStack */, 217 | ); 218 | productName = StackDemoApp; 219 | productReference = 4B2A923928E4B6F9006624AD /* StackDemoApp.app */; 220 | productType = "com.apple.product-type.application"; 221 | }; 222 | 4B2A924728E4B6FA006624AD /* StackDemoAppTests */ = { 223 | isa = PBXNativeTarget; 224 | buildConfigurationList = 4B2A925D28E4B6FA006624AD /* Build configuration list for PBXNativeTarget "StackDemoAppTests" */; 225 | buildPhases = ( 226 | 4B2A924428E4B6FA006624AD /* Sources */, 227 | 4B2A924528E4B6FA006624AD /* Frameworks */, 228 | 4B2A924628E4B6FA006624AD /* Resources */, 229 | ); 230 | buildRules = ( 231 | ); 232 | dependencies = ( 233 | 4B2A924A28E4B6FA006624AD /* PBXTargetDependency */, 234 | ); 235 | name = StackDemoAppTests; 236 | productName = StackDemoAppTests; 237 | productReference = 4B2A924828E4B6FA006624AD /* StackDemoAppTests.xctest */; 238 | productType = "com.apple.product-type.bundle.unit-test"; 239 | }; 240 | 4B2A925128E4B6FA006624AD /* StackDemoAppUITests */ = { 241 | isa = PBXNativeTarget; 242 | buildConfigurationList = 4B2A926028E4B6FA006624AD /* Build configuration list for PBXNativeTarget "StackDemoAppUITests" */; 243 | buildPhases = ( 244 | 4B2A924E28E4B6FA006624AD /* Sources */, 245 | 4B2A924F28E4B6FA006624AD /* Frameworks */, 246 | 4B2A925028E4B6FA006624AD /* Resources */, 247 | ); 248 | buildRules = ( 249 | ); 250 | dependencies = ( 251 | 4B2A925428E4B6FA006624AD /* PBXTargetDependency */, 252 | ); 253 | name = StackDemoAppUITests; 254 | productName = StackDemoAppUITests; 255 | productReference = 4B2A925228E4B6FA006624AD /* StackDemoAppUITests.xctest */; 256 | productType = "com.apple.product-type.bundle.ui-testing"; 257 | }; 258 | /* End PBXNativeTarget section */ 259 | 260 | /* Begin PBXProject section */ 261 | 4B2A91FF28E4B627006624AD /* Project object */ = { 262 | isa = PBXProject; 263 | attributes = { 264 | BuildIndependentTargetsInParallel = 1; 265 | LastSwiftUpdateCheck = 1400; 266 | LastUpgradeCheck = 1400; 267 | TargetAttributes = { 268 | 4B2A923828E4B6F9006624AD = { 269 | CreatedOnToolsVersion = 14.0.1; 270 | }; 271 | 4B2A924728E4B6FA006624AD = { 272 | CreatedOnToolsVersion = 14.0.1; 273 | TestTargetID = 4B2A923828E4B6F9006624AD; 274 | }; 275 | 4B2A925128E4B6FA006624AD = { 276 | CreatedOnToolsVersion = 14.0.1; 277 | TestTargetID = 4B2A923828E4B6F9006624AD; 278 | }; 279 | }; 280 | }; 281 | buildConfigurationList = 4B2A920228E4B627006624AD /* Build configuration list for PBXProject "Stack" */; 282 | compatibilityVersion = "Xcode 14.0"; 283 | developmentRegion = en; 284 | hasScannedForEncodings = 0; 285 | knownRegions = ( 286 | en, 287 | Base, 288 | ); 289 | mainGroup = 4B2A91FE28E4B627006624AD; 290 | packageReferences = ( 291 | 4B6D472129FC2A5900658A0F /* XCRemoteSwiftPackageReference "swiftui-color" */, 292 | ); 293 | productRefGroup = 4B2A920828E4B627006624AD /* Products */; 294 | projectDirPath = ""; 295 | projectRoot = ""; 296 | targets = ( 297 | 4B2A923828E4B6F9006624AD /* StackDemoApp */, 298 | 4B2A924728E4B6FA006624AD /* StackDemoAppTests */, 299 | 4B2A925128E4B6FA006624AD /* StackDemoAppUITests */, 300 | ); 301 | }; 302 | /* End PBXProject section */ 303 | 304 | /* Begin PBXResourcesBuildPhase section */ 305 | 4B2A923728E4B6F9006624AD /* Resources */ = { 306 | isa = PBXResourcesBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | 4B51F641290ACAAE0015CC21 /* Launch Screen.storyboard in Resources */, 310 | 4B2A924328E4B6FA006624AD /* Preview Assets.xcassets in Resources */, 311 | 4B2A924028E4B6FA006624AD /* Assets.xcassets in Resources */, 312 | ); 313 | runOnlyForDeploymentPostprocessing = 0; 314 | }; 315 | 4B2A924628E4B6FA006624AD /* Resources */ = { 316 | isa = PBXResourcesBuildPhase; 317 | buildActionMask = 2147483647; 318 | files = ( 319 | ); 320 | runOnlyForDeploymentPostprocessing = 0; 321 | }; 322 | 4B2A925028E4B6FA006624AD /* Resources */ = { 323 | isa = PBXResourcesBuildPhase; 324 | buildActionMask = 2147483647; 325 | files = ( 326 | ); 327 | runOnlyForDeploymentPostprocessing = 0; 328 | }; 329 | /* End PBXResourcesBuildPhase section */ 330 | 331 | /* Begin PBXSourcesBuildPhase section */ 332 | 4B2A923528E4B6F9006624AD /* Sources */ = { 333 | isa = PBXSourcesBuildPhase; 334 | buildActionMask = 2147483647; 335 | files = ( 336 | 4B15FAB829FFED8A000442FA /* BookMatchedShape.swift in Sources */, 337 | 4B77AA5B28E4BE75006307DA /* BookStackNoPath.swift in Sources */, 338 | 4BCFDBE7290FC271004D58D3 /* BookStack_Grid.swift in Sources */, 339 | 4BC6C24B28E4B8120081E217 /* BookStack.swift in Sources */, 340 | 4B29A6FF29FC5CA1003CCC00 /* Colors.swift in Sources */, 341 | 4BDA70662A0382FE001AC9AF /* IGAppRoot.swift in Sources */, 342 | 4B2A923E28E4B6F9006624AD /* ContentView.swift in Sources */, 343 | 4B77AA5F28E4BF0C006307DA /* Views.swift in Sources */, 344 | 4B77AA6328E54FE9006307DA /* BookNavigationStack.swift in Sources */, 345 | 4B77AA5D28E4BEA2006307DA /* Model.swift in Sources */, 346 | 4BC6C24D28E4B83B0081E217 /* StatefulPage.swift in Sources */, 347 | 4BDA70642A0382F5001AC9AF /* IGTabView.swift in Sources */, 348 | 4B2A923C28E4B6F9006624AD /* AppDelegate.swift in Sources */, 349 | 4B29A6FD29FC5C31003CCC00 /* BookFullScreenStack.swift in Sources */, 350 | 4B77AA6128E4D1F9006307DA /* BookNesting.swift in Sources */, 351 | ); 352 | runOnlyForDeploymentPostprocessing = 0; 353 | }; 354 | 4B2A924428E4B6FA006624AD /* Sources */ = { 355 | isa = PBXSourcesBuildPhase; 356 | buildActionMask = 2147483647; 357 | files = ( 358 | 4B2A924D28E4B6FA006624AD /* StackDemoAppTests.swift in Sources */, 359 | ); 360 | runOnlyForDeploymentPostprocessing = 0; 361 | }; 362 | 4B2A924E28E4B6FA006624AD /* Sources */ = { 363 | isa = PBXSourcesBuildPhase; 364 | buildActionMask = 2147483647; 365 | files = ( 366 | 4B2A925928E4B6FA006624AD /* StackDemoAppUITestsLaunchTests.swift in Sources */, 367 | 4B2A925728E4B6FA006624AD /* StackDemoAppUITests.swift in Sources */, 368 | ); 369 | runOnlyForDeploymentPostprocessing = 0; 370 | }; 371 | /* End PBXSourcesBuildPhase section */ 372 | 373 | /* Begin PBXTargetDependency section */ 374 | 4B2A924A28E4B6FA006624AD /* PBXTargetDependency */ = { 375 | isa = PBXTargetDependency; 376 | target = 4B2A923828E4B6F9006624AD /* StackDemoApp */; 377 | targetProxy = 4B2A924928E4B6FA006624AD /* PBXContainerItemProxy */; 378 | }; 379 | 4B2A925428E4B6FA006624AD /* PBXTargetDependency */ = { 380 | isa = PBXTargetDependency; 381 | target = 4B2A923828E4B6F9006624AD /* StackDemoApp */; 382 | targetProxy = 4B2A925328E4B6FA006624AD /* PBXContainerItemProxy */; 383 | }; 384 | /* End PBXTargetDependency section */ 385 | 386 | /* Begin XCBuildConfiguration section */ 387 | 4B2A922928E4B628006624AD /* Debug */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | ALWAYS_SEARCH_USER_PATHS = NO; 391 | CLANG_ANALYZER_NONNULL = YES; 392 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 393 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 394 | CLANG_ENABLE_MODULES = YES; 395 | CLANG_ENABLE_OBJC_ARC = YES; 396 | CLANG_ENABLE_OBJC_WEAK = YES; 397 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 398 | CLANG_WARN_BOOL_CONVERSION = YES; 399 | CLANG_WARN_COMMA = YES; 400 | CLANG_WARN_CONSTANT_CONVERSION = YES; 401 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 402 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 403 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 404 | CLANG_WARN_EMPTY_BODY = YES; 405 | CLANG_WARN_ENUM_CONVERSION = YES; 406 | CLANG_WARN_INFINITE_RECURSION = YES; 407 | CLANG_WARN_INT_CONVERSION = YES; 408 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 409 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 410 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 411 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 412 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 413 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 414 | CLANG_WARN_STRICT_PROTOTYPES = YES; 415 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 416 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 417 | CLANG_WARN_UNREACHABLE_CODE = YES; 418 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 419 | COPY_PHASE_STRIP = NO; 420 | DEBUG_INFORMATION_FORMAT = dwarf; 421 | ENABLE_STRICT_OBJC_MSGSEND = YES; 422 | ENABLE_TESTABILITY = YES; 423 | GCC_C_LANGUAGE_STANDARD = gnu11; 424 | GCC_DYNAMIC_NO_PIC = NO; 425 | GCC_NO_COMMON_BLOCKS = YES; 426 | GCC_OPTIMIZATION_LEVEL = 0; 427 | GCC_PREPROCESSOR_DEFINITIONS = ( 428 | "DEBUG=1", 429 | "$(inherited)", 430 | ); 431 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 432 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 433 | GCC_WARN_UNDECLARED_SELECTOR = YES; 434 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 435 | GCC_WARN_UNUSED_FUNCTION = YES; 436 | GCC_WARN_UNUSED_VARIABLE = YES; 437 | IPHONEOS_DEPLOYMENT_TARGET = 16.0; 438 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 439 | MTL_FAST_MATH = YES; 440 | ONLY_ACTIVE_ARCH = YES; 441 | SDKROOT = iphoneos; 442 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 443 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 444 | }; 445 | name = Debug; 446 | }; 447 | 4B2A922A28E4B628006624AD /* Release */ = { 448 | isa = XCBuildConfiguration; 449 | buildSettings = { 450 | ALWAYS_SEARCH_USER_PATHS = NO; 451 | CLANG_ANALYZER_NONNULL = YES; 452 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 453 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 454 | CLANG_ENABLE_MODULES = YES; 455 | CLANG_ENABLE_OBJC_ARC = YES; 456 | CLANG_ENABLE_OBJC_WEAK = YES; 457 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 458 | CLANG_WARN_BOOL_CONVERSION = YES; 459 | CLANG_WARN_COMMA = YES; 460 | CLANG_WARN_CONSTANT_CONVERSION = YES; 461 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 462 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 463 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 464 | CLANG_WARN_EMPTY_BODY = YES; 465 | CLANG_WARN_ENUM_CONVERSION = YES; 466 | CLANG_WARN_INFINITE_RECURSION = YES; 467 | CLANG_WARN_INT_CONVERSION = YES; 468 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 469 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 470 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 471 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 472 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 473 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 474 | CLANG_WARN_STRICT_PROTOTYPES = YES; 475 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 476 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 477 | CLANG_WARN_UNREACHABLE_CODE = YES; 478 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 479 | COPY_PHASE_STRIP = NO; 480 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 481 | ENABLE_NS_ASSERTIONS = NO; 482 | ENABLE_STRICT_OBJC_MSGSEND = YES; 483 | GCC_C_LANGUAGE_STANDARD = gnu11; 484 | GCC_NO_COMMON_BLOCKS = YES; 485 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 486 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 487 | GCC_WARN_UNDECLARED_SELECTOR = YES; 488 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 489 | GCC_WARN_UNUSED_FUNCTION = YES; 490 | GCC_WARN_UNUSED_VARIABLE = YES; 491 | IPHONEOS_DEPLOYMENT_TARGET = 16.0; 492 | MTL_ENABLE_DEBUG_INFO = NO; 493 | MTL_FAST_MATH = YES; 494 | SDKROOT = iphoneos; 495 | SWIFT_COMPILATION_MODE = wholemodule; 496 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 497 | VALIDATE_PRODUCT = YES; 498 | }; 499 | name = Release; 500 | }; 501 | 4B2A925B28E4B6FA006624AD /* Debug */ = { 502 | isa = XCBuildConfiguration; 503 | buildSettings = { 504 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 505 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 506 | CODE_SIGN_STYLE = Automatic; 507 | CURRENT_PROJECT_VERSION = 1; 508 | DEVELOPMENT_ASSET_PATHS = "\"StackDemoApp/Preview Content\""; 509 | DEVELOPMENT_TEAM = JX92XL88RZ; 510 | ENABLE_PREVIEWS = YES; 511 | GENERATE_INFOPLIST_FILE = YES; 512 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 513 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 514 | INFOPLIST_KEY_UILaunchStoryboardName = "Launch Screen.storyboard"; 515 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 516 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 517 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 518 | LD_RUNPATH_SEARCH_PATHS = ( 519 | "$(inherited)", 520 | "@executable_path/Frameworks", 521 | ); 522 | MARKETING_VERSION = 1.0; 523 | PRODUCT_BUNDLE_IDENTIFIER = app.muukii.StackDemoApp; 524 | PRODUCT_NAME = "$(TARGET_NAME)"; 525 | SWIFT_EMIT_LOC_STRINGS = YES; 526 | SWIFT_VERSION = 5.0; 527 | TARGETED_DEVICE_FAMILY = "1,2"; 528 | }; 529 | name = Debug; 530 | }; 531 | 4B2A925C28E4B6FA006624AD /* Release */ = { 532 | isa = XCBuildConfiguration; 533 | buildSettings = { 534 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 535 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 536 | CODE_SIGN_STYLE = Automatic; 537 | CURRENT_PROJECT_VERSION = 1; 538 | DEVELOPMENT_ASSET_PATHS = "\"StackDemoApp/Preview Content\""; 539 | DEVELOPMENT_TEAM = JX92XL88RZ; 540 | ENABLE_PREVIEWS = YES; 541 | GENERATE_INFOPLIST_FILE = YES; 542 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 543 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 544 | INFOPLIST_KEY_UILaunchStoryboardName = "Launch Screen.storyboard"; 545 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 546 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 547 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 548 | LD_RUNPATH_SEARCH_PATHS = ( 549 | "$(inherited)", 550 | "@executable_path/Frameworks", 551 | ); 552 | MARKETING_VERSION = 1.0; 553 | PRODUCT_BUNDLE_IDENTIFIER = app.muukii.StackDemoApp; 554 | PRODUCT_NAME = "$(TARGET_NAME)"; 555 | SWIFT_EMIT_LOC_STRINGS = YES; 556 | SWIFT_VERSION = 5.0; 557 | TARGETED_DEVICE_FAMILY = "1,2"; 558 | }; 559 | name = Release; 560 | }; 561 | 4B2A925E28E4B6FA006624AD /* Debug */ = { 562 | isa = XCBuildConfiguration; 563 | buildSettings = { 564 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 565 | BUNDLE_LOADER = "$(TEST_HOST)"; 566 | CODE_SIGN_STYLE = Automatic; 567 | CURRENT_PROJECT_VERSION = 1; 568 | GENERATE_INFOPLIST_FILE = YES; 569 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 570 | MARKETING_VERSION = 1.0; 571 | PRODUCT_BUNDLE_IDENTIFIER = app.muukii.StackDemoAppTests; 572 | PRODUCT_NAME = "$(TARGET_NAME)"; 573 | SWIFT_EMIT_LOC_STRINGS = NO; 574 | SWIFT_VERSION = 5.0; 575 | TARGETED_DEVICE_FAMILY = "1,2"; 576 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/StackDemoApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/StackDemoApp"; 577 | }; 578 | name = Debug; 579 | }; 580 | 4B2A925F28E4B6FA006624AD /* Release */ = { 581 | isa = XCBuildConfiguration; 582 | buildSettings = { 583 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 584 | BUNDLE_LOADER = "$(TEST_HOST)"; 585 | CODE_SIGN_STYLE = Automatic; 586 | CURRENT_PROJECT_VERSION = 1; 587 | GENERATE_INFOPLIST_FILE = YES; 588 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 589 | MARKETING_VERSION = 1.0; 590 | PRODUCT_BUNDLE_IDENTIFIER = app.muukii.StackDemoAppTests; 591 | PRODUCT_NAME = "$(TARGET_NAME)"; 592 | SWIFT_EMIT_LOC_STRINGS = NO; 593 | SWIFT_VERSION = 5.0; 594 | TARGETED_DEVICE_FAMILY = "1,2"; 595 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/StackDemoApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/StackDemoApp"; 596 | }; 597 | name = Release; 598 | }; 599 | 4B2A926128E4B6FA006624AD /* Debug */ = { 600 | isa = XCBuildConfiguration; 601 | buildSettings = { 602 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 603 | CODE_SIGN_STYLE = Automatic; 604 | CURRENT_PROJECT_VERSION = 1; 605 | GENERATE_INFOPLIST_FILE = YES; 606 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 607 | MARKETING_VERSION = 1.0; 608 | PRODUCT_BUNDLE_IDENTIFIER = app.muukii.StackDemoAppUITests; 609 | PRODUCT_NAME = "$(TARGET_NAME)"; 610 | SWIFT_EMIT_LOC_STRINGS = NO; 611 | SWIFT_VERSION = 5.0; 612 | TARGETED_DEVICE_FAMILY = "1,2"; 613 | TEST_TARGET_NAME = StackDemoApp; 614 | }; 615 | name = Debug; 616 | }; 617 | 4B2A926228E4B6FA006624AD /* Release */ = { 618 | isa = XCBuildConfiguration; 619 | buildSettings = { 620 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 621 | CODE_SIGN_STYLE = Automatic; 622 | CURRENT_PROJECT_VERSION = 1; 623 | GENERATE_INFOPLIST_FILE = YES; 624 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 625 | MARKETING_VERSION = 1.0; 626 | PRODUCT_BUNDLE_IDENTIFIER = app.muukii.StackDemoAppUITests; 627 | PRODUCT_NAME = "$(TARGET_NAME)"; 628 | SWIFT_EMIT_LOC_STRINGS = NO; 629 | SWIFT_VERSION = 5.0; 630 | TARGETED_DEVICE_FAMILY = "1,2"; 631 | TEST_TARGET_NAME = StackDemoApp; 632 | }; 633 | name = Release; 634 | }; 635 | /* End XCBuildConfiguration section */ 636 | 637 | /* Begin XCConfigurationList section */ 638 | 4B2A920228E4B627006624AD /* Build configuration list for PBXProject "Stack" */ = { 639 | isa = XCConfigurationList; 640 | buildConfigurations = ( 641 | 4B2A922928E4B628006624AD /* Debug */, 642 | 4B2A922A28E4B628006624AD /* Release */, 643 | ); 644 | defaultConfigurationIsVisible = 0; 645 | defaultConfigurationName = Release; 646 | }; 647 | 4B2A925A28E4B6FA006624AD /* Build configuration list for PBXNativeTarget "StackDemoApp" */ = { 648 | isa = XCConfigurationList; 649 | buildConfigurations = ( 650 | 4B2A925B28E4B6FA006624AD /* Debug */, 651 | 4B2A925C28E4B6FA006624AD /* Release */, 652 | ); 653 | defaultConfigurationIsVisible = 0; 654 | defaultConfigurationName = Release; 655 | }; 656 | 4B2A925D28E4B6FA006624AD /* Build configuration list for PBXNativeTarget "StackDemoAppTests" */ = { 657 | isa = XCConfigurationList; 658 | buildConfigurations = ( 659 | 4B2A925E28E4B6FA006624AD /* Debug */, 660 | 4B2A925F28E4B6FA006624AD /* Release */, 661 | ); 662 | defaultConfigurationIsVisible = 0; 663 | defaultConfigurationName = Release; 664 | }; 665 | 4B2A926028E4B6FA006624AD /* Build configuration list for PBXNativeTarget "StackDemoAppUITests" */ = { 666 | isa = XCConfigurationList; 667 | buildConfigurations = ( 668 | 4B2A926128E4B6FA006624AD /* Debug */, 669 | 4B2A926228E4B6FA006624AD /* Release */, 670 | ); 671 | defaultConfigurationIsVisible = 0; 672 | defaultConfigurationName = Release; 673 | }; 674 | /* End XCConfigurationList section */ 675 | 676 | /* Begin XCRemoteSwiftPackageReference section */ 677 | 4B6D472129FC2A5900658A0F /* XCRemoteSwiftPackageReference "swiftui-color" */ = { 678 | isa = XCRemoteSwiftPackageReference; 679 | repositoryURL = "https://github.com/FluidGroup/swiftui-color.git"; 680 | requirement = { 681 | kind = upToNextMajorVersion; 682 | minimumVersion = 1.0.0; 683 | }; 684 | }; 685 | /* End XCRemoteSwiftPackageReference section */ 686 | 687 | /* Begin XCSwiftPackageProductDependency section */ 688 | 4B6D472229FC2A5900658A0F /* swiftui-color */ = { 689 | isa = XCSwiftPackageProductDependency; 690 | package = 4B6D472129FC2A5900658A0F /* XCRemoteSwiftPackageReference "swiftui-color" */; 691 | productName = "swiftui-color"; 692 | }; 693 | 4BC315B32A09423600D86A6C /* SwiftUIStack */ = { 694 | isa = XCSwiftPackageProductDependency; 695 | productName = SwiftUIStack; 696 | }; 697 | /* End XCSwiftPackageProductDependency section */ 698 | }; 699 | rootObject = 4B2A91FF28E4B627006624AD /* Project object */; 700 | } 701 | -------------------------------------------------------------------------------- /StackApp/Stack.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /StackApp/Stack.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /StackApp/Stack.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "fluidinterfacekit", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/FluidGroup/FluidInterfaceKit.git", 7 | "state" : { 8 | "revision" : "6fff632e5ec299c6f99968f96b84732e3ae76fc8", 9 | "version" : "0.6.1" 10 | } 11 | }, 12 | { 13 | "identity" : "geometrykit", 14 | "kind" : "remoteSourceControl", 15 | "location" : "https://github.com/FluidGroup/GeometryKit", 16 | "state" : { 17 | "revision" : "6cf96dcb220e1b612ba57a717234cbdbf877c009", 18 | "version" : "1.1.0" 19 | } 20 | }, 21 | { 22 | "identity" : "matchedtransition", 23 | "kind" : "remoteSourceControl", 24 | "location" : "https://github.com/FluidGroup/MatchedTransition", 25 | "state" : { 26 | "revision" : "bf97b6f5e133a6ffbc34ac7ca36f355eec84d3af", 27 | "version" : "1.3.0" 28 | } 29 | }, 30 | { 31 | "identity" : "resultbuilderkit", 32 | "kind" : "remoteSourceControl", 33 | "location" : "https://github.com/FluidGroup/ResultBuilderKit.git", 34 | "state" : { 35 | "revision" : "34aa57fcee5ec3ee0f368b05cb53c7919c188ab2", 36 | "version" : "1.3.0" 37 | } 38 | }, 39 | { 40 | "identity" : "rideau", 41 | "kind" : "remoteSourceControl", 42 | "location" : "https://github.com/FluidGroup/Rideau.git", 43 | "state" : { 44 | "revision" : "f803dc498fe79da483173daf3b04a2a23ef1a9c2", 45 | "version" : "2.2.0" 46 | } 47 | } 48 | ], 49 | "version" : 2 50 | } 51 | -------------------------------------------------------------------------------- /StackApp/Stack.xcodeproj/xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 16 | 17 | 19 | 21 | 22 | 23 | 24 | 25 | 34 | 35 | 44 | 45 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /StackApp/Stack.xcodeproj/xcshareddata/xcschemes/StackDemoApp.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 57 | 63 | 64 | 65 | 71 | 77 | 78 | 79 | 80 | 81 | 86 | 87 | 90 | 96 | 97 | 98 | 101 | 107 | 108 | 109 | 111 | 117 | 118 | 119 | 120 | 121 | 131 | 133 | 139 | 140 | 141 | 142 | 148 | 150 | 156 | 157 | 158 | 159 | 161 | 162 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | @_exported import SwiftUI 4 | 5 | @UIApplicationMain 6 | public class AppDelegate: UIResponder, UIApplicationDelegate { 7 | 8 | public var window: UIWindow? 9 | 10 | public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 11 | // Override point for customization after application launch. 12 | 13 | let window = UIWindow() 14 | window.rootViewController = UIHostingController(rootView: ContentView()) 15 | self.window = window 16 | window.makeKeyAndVisible() 17 | 18 | return true 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/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 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | } 8 | ], 9 | "info" : { 10 | "author" : "xcode", 11 | "version" : 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/BookFullScreenStack.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import SwiftUIStack 3 | import SwiftUISupport 4 | 5 | struct BookFullScreenStack: View, PreviewProvider { 6 | 7 | @State var path: StackPath = .init([ 8 | // Post( 9 | // id: "slide", 10 | // artworkImageURL: nil, 11 | // title: "Push style transition", 12 | // subTitle: "Supports gesture to pop", 13 | // body: "" 14 | // ) 15 | ] as [Post]) 16 | 17 | var body: some View { 18 | Root(path: $path) 19 | } 20 | 21 | static var previews: some View { 22 | Self() 23 | 24 | PostDetail( 25 | colorScheme: .type10, 26 | post: Post( 27 | id: "slide", 28 | artworkImageURL: nil, 29 | title: "Push style transition", 30 | subTitle: "Supports gesture to pop", 31 | body: "" 32 | ) 33 | ) 34 | 35 | } 36 | 37 | private struct ContentFragment: View { 38 | 39 | let colorScheme: ColorScheme 40 | 41 | let users: [Node] = User.generateDummyUsers().map { .user($0) } 42 | 43 | let postsForCarousel: [Post] = [ 44 | Post( 45 | id: "carousel-1", 46 | artworkImageURL: nil, 47 | title: "Carousel", 48 | subTitle: "Tap to see", 49 | body: "" 50 | ), 51 | Post( 52 | id: "carousel-2", 53 | artworkImageURL: nil, 54 | title: "Carousel", 55 | subTitle: "Tap to see", 56 | body: "" 57 | ), 58 | Post( 59 | id: "carousel-3", 60 | artworkImageURL: nil, 61 | title: "Carousel", 62 | subTitle: "Tap to see", 63 | body: "" 64 | ), 65 | Post( 66 | id: "carousel-4", 67 | artworkImageURL: nil, 68 | title: "Carousel", 69 | subTitle: "Tap to see", 70 | body: "" 71 | ), 72 | Post( 73 | id: "carousel-5", 74 | artworkImageURL: nil, 75 | title: "Carousel", 76 | subTitle: "Tap to see", 77 | body: "" 78 | ), 79 | Post( 80 | id: "carousel-6", 81 | artworkImageURL: nil, 82 | title: "Carousel", 83 | subTitle: "Tap to see", 84 | body: "" 85 | ), 86 | ] 87 | 88 | let postsForList: [Post] = [ 89 | Post( 90 | id: "a", 91 | artworkImageURL: nil, 92 | title: "Contextual style transition", 93 | subTitle: "Tap to see", 94 | body: "" 95 | ) 96 | ] 97 | 98 | let dataForSlideTransition = Post( 99 | id: "slide", 100 | artworkImageURL: nil, 101 | title: "Push style transition", 102 | subTitle: "Supports gesture to pop", 103 | body: "" 104 | ) 105 | 106 | let postsForGrid: [Post] = [ 107 | Post( 108 | id: "grid-1", 109 | artworkImageURL: nil, 110 | title: "Grid", 111 | subTitle: "Tap to see", 112 | body: "" 113 | ), 114 | Post( 115 | id: "grid-2", 116 | artworkImageURL: nil, 117 | title: "Grid", 118 | subTitle: "Tap to see", 119 | body: "" 120 | ), 121 | Post( 122 | id: "grid-3", 123 | artworkImageURL: nil, 124 | title: "Grid", 125 | subTitle: "Tap to see", 126 | body: "" 127 | ), 128 | Post( 129 | id: "grid-4", 130 | artworkImageURL: nil, 131 | title: "Grid", 132 | subTitle: "Tap to see", 133 | body: "" 134 | ), 135 | ] 136 | 137 | @Namespace var local 138 | 139 | var body: some View { 140 | 141 | LazyVStack(spacing: 16) { 142 | // 143 | // carousel 144 | ScrollView(.horizontal) { 145 | LazyHStack { 146 | 147 | ForEach(postsForCarousel) { post in 148 | StackLink( 149 | transition: .matched(identifier: post.id.description + "Shaped", in: local), 150 | value: post 151 | ) { 152 | ShapedGridCell(colorScheme: colorScheme, post: post) 153 | } 154 | } 155 | 156 | } 157 | .padding(.horizontal, 16) 158 | } 159 | 160 | ScrollView(.horizontal) { 161 | LazyHStack { 162 | 163 | ForEach(postsForCarousel) { post in 164 | StackLink( 165 | transition: .matched(identifier: post.id.description + "non", in: local), 166 | value: post 167 | ) { 168 | GridCell(colorScheme: colorScheme, post: post) 169 | } 170 | } 171 | 172 | } 173 | .padding(.horizontal, 16) 174 | } 175 | 176 | StackLink(transition: .slide, value: dataForSlideTransition) { 177 | ShapedPostCell(colorScheme: colorScheme, post: dataForSlideTransition) 178 | } 179 | .padding(.horizontal, 16) 180 | 181 | LazyVStack { 182 | 183 | ForEach(postsForList) { post in 184 | StackLink( 185 | transition: .matched(identifier: post.id.description + "Shaped", in: local), 186 | value: post 187 | ) { 188 | ShapedPostCell(colorScheme: colorScheme, post: post) 189 | } 190 | } 191 | 192 | } 193 | .padding(.horizontal, 16) 194 | 195 | LazyVStack { 196 | 197 | ForEach(postsForList) { post in 198 | StackLink( 199 | transition: .matched(identifier: post.id.description + "Non", in: local), 200 | value: post 201 | ) { 202 | PostCell(colorScheme: colorScheme, post: post) 203 | } 204 | } 205 | 206 | } 207 | .padding(.horizontal, 16) 208 | 209 | LazyVGrid(columns: [.init(.flexible()), .init(.flexible())]) { 210 | 211 | ForEach(postsForGrid) { post in 212 | StackLink( 213 | transition: .matched(identifier: post.id.description + "Shaped", in: local), 214 | value: post 215 | ) { 216 | ShapedPostCell(colorScheme: colorScheme, post: post) 217 | } 218 | } 219 | 220 | } 221 | .padding(.horizontal, 16) 222 | 223 | LazyVGrid(columns: [.init(.flexible()), .init(.flexible())]) { 224 | 225 | ForEach(postsForGrid) { post in 226 | StackLink( 227 | transition: .matched(identifier: post.id.description + "Non", in: local), 228 | value: post 229 | ) { 230 | PostCell(colorScheme: colorScheme, post: post) 231 | } 232 | } 233 | 234 | } 235 | .padding(.horizontal, 16) 236 | 237 | } 238 | } 239 | } 240 | 241 | enum Node: Hashable, Identifiable { 242 | case user(User) 243 | 244 | var id: String { 245 | switch self { 246 | case .user(let user): 247 | return "user_\(user.id)" 248 | } 249 | } 250 | 251 | } 252 | 253 | struct ShapedGridCell: View { 254 | let colorScheme: ColorScheme 255 | let post: Post 256 | 257 | var body: some View { 258 | 259 | VStack(alignment: .leading) { 260 | VStack(spacing: 0) { 261 | Circle() 262 | .fill(Color.init(white: 0.5, opacity: 0.3)) 263 | .frame( 264 | width: 40, 265 | height: 40, 266 | alignment: .center 267 | ) 268 | } 269 | } 270 | .padding(12) 271 | .background( 272 | RoundedRectangle( 273 | cornerRadius: 8, 274 | style: .continuous 275 | ) 276 | .fill( 277 | colorScheme.cardBackground 278 | ) 279 | ) 280 | 281 | } 282 | } 283 | 284 | struct GridCell: View { 285 | let colorScheme: ColorScheme 286 | let post: Post 287 | 288 | var body: some View { 289 | 290 | VStack(alignment: .leading) { 291 | VStack(spacing: 0) { 292 | Circle() 293 | .fill(Color.init(white: 0.5, opacity: 0.3)) 294 | .frame( 295 | width: 40, 296 | height: 40, 297 | alignment: .center 298 | ) 299 | } 300 | } 301 | .padding(12) 302 | } 303 | } 304 | 305 | struct ShapedListCell: View { 306 | 307 | let colorScheme: ColorScheme 308 | let user: User 309 | 310 | var body: some View { 311 | 312 | VStack(alignment: .leading) { 313 | HStack(spacing: 12) { 314 | Circle() 315 | .fill(Color.init(white: 0.5, opacity: 0.3)) 316 | .frame( 317 | width: 40, 318 | height: 40, 319 | alignment: .center 320 | ) 321 | 322 | Text(user.name) 323 | .font(.system(.body, design: .default)) 324 | .foregroundColor(colorScheme.cardHeadline) 325 | 326 | Text(user.age.description) 327 | .foregroundColor(colorScheme.cardParagraph) 328 | 329 | Spacer() 330 | } 331 | } 332 | .padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12)) 333 | .background( 334 | RoundedRectangle( 335 | cornerRadius: 8, 336 | style: .continuous 337 | ) 338 | .fill( 339 | colorScheme.cardBackground 340 | ) 341 | ) 342 | 343 | } 344 | 345 | } 346 | 347 | private struct Root: View { 348 | 349 | let colorScheme = ColorScheme.type10 350 | 351 | @Environment(\.stackUnwindContext) var unwindContext 352 | 353 | @State var lastColorScheme = ColorScheme.type10 354 | 355 | @Binding var path: StackPath 356 | 357 | var body: some View { 358 | ZStack { 359 | 360 | colorScheme.background 361 | .ignoresSafeArea() 362 | 363 | Stack(path: $path) { 364 | 365 | ScrollView { 366 | VStack { 367 | StackUnwindLink(target: .specific(unwindContext)) { 368 | Text("back to menu") 369 | } 370 | ContentFragment(colorScheme: colorScheme) 371 | } 372 | } 373 | .stackDestination( 374 | for: User.self, 375 | destination: { user in 376 | Detail(user: user, colorScheme: .takeOne(except: colorScheme)) 377 | } 378 | ) 379 | .stackDestination(for: Post.self) { post in 380 | // not good 381 | let _ = self.lastColorScheme = ColorScheme.takeOne(except: lastColorScheme) 382 | PostDetail(colorScheme: .takeOne(except: lastColorScheme), post: post) 383 | } 384 | 385 | } 386 | 387 | } 388 | } 389 | } 390 | 391 | struct Detail: View { 392 | 393 | let user: User 394 | var colorScheme: ColorScheme 395 | 396 | @Namespace var local 397 | 398 | var body: some View { 399 | 400 | ZStack { 401 | 402 | StackBackground { 403 | colorScheme.background 404 | } 405 | 406 | ScrollView { 407 | VStack { 408 | 409 | Text(user.name) 410 | .font(.system(.body, design: .default)) 411 | .foregroundColor(colorScheme.paragraph) 412 | 413 | Text(user.age.description) 414 | .font(.system(.body, design: .default)) 415 | .foregroundColor(colorScheme.paragraph) 416 | 417 | Spacer() 418 | 419 | VStack { 420 | 421 | HStack { 422 | StackUnwindLink { 423 | Text("Back") 424 | } 425 | Spacer() 426 | StackUnwindLink(mode: .all) { 427 | Text("Back to Root") 428 | } 429 | } 430 | 431 | StackLink(transition: .matched(identifier: user.id, in: local)) { 432 | Detail(user: user, colorScheme: .takeOne(except: colorScheme)) 433 | } label: { 434 | ShapedListCell(colorScheme: colorScheme, user: user) 435 | } 436 | 437 | } 438 | .padding(.horizontal, 16) 439 | 440 | ContentFragment(colorScheme: colorScheme) 441 | } 442 | } 443 | } 444 | 445 | } 446 | 447 | } 448 | 449 | // struct Hashed: Hashable { 450 | // 451 | // let idKeyPath: KeyPath 452 | // let value: Value 453 | // 454 | // func hash(into hasher: inout Hasher) { 455 | // value[keyPath: idKeyPath].hash(into: &hasher) 456 | // } 457 | // 458 | // init(_ value: Value, id: KeyPath) { 459 | // self.value = value 460 | // self.idKeyPath = id 461 | // } 462 | // 463 | // } 464 | 465 | struct Post: Identifiable, Hashable { 466 | 467 | let id: String 468 | 469 | let artworkImageURL: URL? 470 | let title: String 471 | let subTitle: String 472 | let body: String 473 | 474 | } 475 | 476 | struct ShapedPostCell: View { 477 | 478 | let colorScheme: ColorScheme 479 | let post: Post 480 | 481 | var body: some View { 482 | 483 | VStack(alignment: .leading) { 484 | HStack(spacing: 12) { 485 | RoundedRectangle(cornerRadius: 4, style: .continuous) 486 | .fill(colorScheme.background) 487 | .frame( 488 | width: 40, 489 | height: 40, 490 | alignment: .center 491 | ) 492 | 493 | VStack(alignment: .leading) { 494 | Text(post.title) 495 | .font(.system(.body, design: .default)) 496 | .foregroundColor(colorScheme.cardHeadline) 497 | 498 | Text(post.subTitle) 499 | .foregroundColor(colorScheme.cardParagraph) 500 | } 501 | 502 | Spacer() 503 | } 504 | } 505 | .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 12)) 506 | .background( 507 | RoundedRectangle( 508 | cornerRadius: 8, 509 | style: .continuous 510 | ) 511 | .fill( 512 | colorScheme.cardBackground 513 | ) 514 | ) 515 | } 516 | 517 | } 518 | 519 | struct PostCell: View { 520 | 521 | let colorScheme: ColorScheme 522 | let post: Post 523 | 524 | var body: some View { 525 | 526 | VStack(alignment: .leading) { 527 | HStack(spacing: 12) { 528 | RoundedRectangle(cornerRadius: 4, style: .continuous) 529 | .fill(colorScheme.cardBackground) 530 | .frame( 531 | width: 40, 532 | height: 40, 533 | alignment: .center 534 | ) 535 | 536 | VStack(alignment: .leading) { 537 | Text(post.title) 538 | .font(.system(.body, design: .default)) 539 | .foregroundColor(colorScheme.headline) 540 | 541 | Text(post.subTitle) 542 | .foregroundColor(colorScheme.paragraph) 543 | } 544 | 545 | Spacer() 546 | } 547 | } 548 | .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 12)) 549 | 550 | } 551 | 552 | } 553 | 554 | struct PostDetail: View { 555 | 556 | let colorScheme: ColorScheme 557 | let post: Post 558 | 559 | var body: some View { 560 | ZStack { 561 | 562 | StackBackground { 563 | colorScheme.background 564 | } 565 | 566 | ScrollView { 567 | VStack { 568 | 569 | Text(post.title) 570 | .font(.system(.body, design: .default)) 571 | .foregroundColor(colorScheme.paragraph) 572 | 573 | Text(post.subTitle) 574 | .font(.system(.body, design: .default)) 575 | .foregroundColor(colorScheme.paragraph) 576 | 577 | Text(post.body) 578 | .font(.system(.body, design: .default)) 579 | .foregroundColor(colorScheme.paragraph) 580 | 581 | Spacer() 582 | 583 | StackUnwindLink { 584 | Text("Back") 585 | } 586 | 587 | Text("Others") 588 | .font(.title2) 589 | .foregroundColor(colorScheme.headline) 590 | .relative(horizontal: .leading) 591 | .padding(.horizontal, 16) 592 | 593 | ContentFragment(colorScheme: colorScheme) 594 | } 595 | } 596 | } 597 | } 598 | 599 | } 600 | 601 | struct User: Hashable, Identifiable { 602 | let id: UUID 603 | let name: String 604 | let age: Int 605 | let profileDescription: String 606 | 607 | static func generateDummyUsers() -> [User] { 608 | return [ 609 | User( 610 | id: UUID(), 611 | name: "User 1", 612 | age: 62, 613 | profileDescription: "User 1 is an award-winning writer." 614 | ), 615 | User( 616 | id: UUID(), 617 | name: "User 2", 618 | age: 47, 619 | profileDescription: "User 2 is known for her best-selling novels." 620 | ), 621 | User( 622 | id: UUID(), 623 | name: "User 3", 624 | age: 42, 625 | profileDescription: "User 3 is a renowned manga artist." 626 | ), 627 | User( 628 | id: UUID(), 629 | name: "User 4", 630 | age: 32, 631 | profileDescription: "User 4 is a famous travel writer." 632 | ), 633 | // Add more users as needed 634 | ] 635 | } 636 | } 637 | 638 | } 639 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/BookMatchedShape.swift: -------------------------------------------------------------------------------- 1 | @_spi(Internal) import SwiftUIStack 2 | import SwiftUI 3 | import SwiftUISnapDraggingModifier 4 | import SwiftUISupport 5 | 6 | struct BookMatchedShape: View, PreviewProvider { 7 | var body: some View { 8 | __Stack() 9 | } 10 | 11 | static var previews: some View { 12 | Self() 13 | } 14 | 15 | private final class Controller: ObservableObject { 16 | 17 | @Published var details: [AnyView] = [] 18 | 19 | } 20 | 21 | private struct Link: View { 22 | 23 | @EnvironmentObject var controller: Controller 24 | @Environment(\.stackNamespaceID) var local_tmp 25 | var local: Namespace.ID { 26 | local_tmp! 27 | } 28 | 29 | var isActive: Bool { 30 | controller.details.isEmpty == false 31 | } 32 | 33 | var body: some View { 34 | // subject 35 | let item = ContainerView { 36 | 37 | ZStack { 38 | ColorScheme.type1.background 39 | VStack(alignment: .leading) { 40 | HStack(spacing: 12) { 41 | Circle() 42 | .frame( 43 | width: 40, 44 | height: 40, 45 | alignment: .center 46 | ) 47 | 48 | Text("Name") 49 | .font(.system(.body, design: .default)) 50 | 51 | Text("30") 52 | .font(.system(.body, design: .default)) 53 | } 54 | .padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12)) 55 | } 56 | .blur(radius: isActive ? 30 : 0) 57 | } 58 | 59 | } 60 | 61 | .matchedGeometryEffect( 62 | id: "movement", 63 | in: local, 64 | properties: [.frame], 65 | isSource: false 66 | ) 67 | 68 | .matchedGeometryEffect( 69 | id: "frame", 70 | in: local, 71 | properties: [.frame], 72 | isSource: isActive == false 73 | ) 74 | .onTapGesture { 75 | 76 | withAnimation( 77 | .interactiveSpring(response: 0.4, dampingFraction: 0.8, blendDuration: 0) 78 | ) { 79 | 80 | addDetail() 81 | 82 | } 83 | } 84 | .zIndex(isActive ? 0 : 1) 85 | 86 | item 87 | } 88 | 89 | private func addDetail() { 90 | let destination = ContainerView { 91 | ZStack { 92 | 93 | ColorScheme.type2.background 94 | 95 | VStack { 96 | HStack { 97 | Button("Dismiss") { 98 | } 99 | } 100 | Circle() 101 | .frame( 102 | width: 100, 103 | height: 100, 104 | alignment: .center 105 | ) 106 | 107 | Circle() 108 | .frame( 109 | width: 100, 110 | height: 100, 111 | alignment: .center 112 | ) 113 | 114 | Circle() 115 | .frame( 116 | width: 100, 117 | height: 100, 118 | alignment: .center 119 | ) 120 | 121 | Text("Hello") 122 | } 123 | } 124 | } 125 | 126 | .transition( 127 | AnyTransition.modifier( 128 | active: StyleModifier(opacity: 0, blurRadius: 30), 129 | identity: .identity 130 | ) 131 | ) 132 | 133 | .matchedGeometryEffect( 134 | id: "movement", 135 | in: local, 136 | properties: [], 137 | isSource: true 138 | ) 139 | .modifier( 140 | SnapDraggingModifier( 141 | springParameter: .interpolation(mass: 1, stiffness: 80, damping: 13), 142 | handler: .init(onEndDragging: { velocity, offset, size in 143 | 144 | withAnimation(.interpolatingSpring(mass: 1, stiffness: 80, damping: 13)) { 145 | controller.details = [] 146 | } 147 | 148 | return .zero 149 | }) 150 | ) 151 | ) 152 | .matchedGeometryEffect( 153 | id: "frame", 154 | in: local, 155 | properties: [.frame], 156 | isSource: true 157 | ) 158 | 159 | // simulate in Stack 160 | controller.details.append(AnyView(destination)) 161 | 162 | } 163 | } 164 | 165 | private struct __Stack: View { 166 | 167 | @StateObject var controller = Controller() 168 | var hasDetail: Bool { 169 | controller.details.isEmpty == false 170 | } 171 | @Namespace var local 172 | 173 | var body: some View { 174 | 175 | ZStack { 176 | 177 | ZStack { 178 | 179 | VStack { 180 | 181 | // accessories 182 | do { 183 | RoundedRectangle(cornerRadius: 16, style: .continuous) 184 | .fill(ColorScheme.type4.background) 185 | Spacer() 186 | } 187 | 188 | // accessories 189 | do { 190 | RoundedRectangle(cornerRadius: 16, style: .continuous) 191 | .fill(ColorScheme.type4.background) 192 | Spacer() 193 | } 194 | 195 | // accessories 196 | do { 197 | RoundedRectangle(cornerRadius: 16, style: .continuous) 198 | .fill(ColorScheme.type4.background) 199 | Spacer() 200 | } 201 | 202 | Link() 203 | 204 | // accessories 205 | do { 206 | RoundedRectangle(cornerRadius: 16, style: .continuous) 207 | .fill(ColorScheme.type4.background) 208 | Spacer() 209 | } 210 | 211 | } 212 | 213 | } 214 | 215 | ForEach.inefficient(items: controller.details) { view in 216 | view 217 | } 218 | 219 | } 220 | .environment(\.stackNamespaceID, local) 221 | .environmentObject(controller) 222 | 223 | } 224 | 225 | } 226 | 227 | struct ContainerView: View { 228 | 229 | private let content: Content 230 | 231 | init(@ViewBuilder content: () -> Content) { 232 | self.content = content() 233 | } 234 | 235 | var body: some View { 236 | ZStack { 237 | Color.clear 238 | content 239 | .frame(minWidth: 0, minHeight: 0, alignment: .top) 240 | } 241 | .clipped() 242 | .background( 243 | RoundedRectangle(cornerRadius: 16, style: .continuous) 244 | .fill(Color.clear) 245 | ) 246 | } 247 | 248 | } 249 | 250 | enum ContainerView_Preview: PreviewProvider { 251 | 252 | static var previews: some View { 253 | 254 | ContainerView { 255 | VStack { 256 | Text("Hello") 257 | Text("Hello") 258 | Text("Hello") 259 | Text("Hello") 260 | Text("Hello") 261 | } 262 | } 263 | .frame(maxWidth: 100, maxHeight: 40, alignment: .top) 264 | 265 | VStack { 266 | Text("1") 267 | Text("2") 268 | Text("3") 269 | Text("4") 270 | Text("5") 271 | } 272 | .frame(minWidth: 0, minHeight: 0, idealHeight: 10, maxHeight: 40, alignment: .top) 273 | .clipped() 274 | 275 | } 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/BookNavigationStack.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct BookNavigationStack: View { 4 | 5 | var body: some View { 6 | 7 | if #available(iOS 16, *) { 8 | _BookNavigationStack() 9 | } 10 | 11 | } 12 | } 13 | 14 | @available(iOS 16, *) 15 | private struct _BookNavigationStack: View { 16 | 17 | struct A: Hashable { 18 | var id: String 19 | } 20 | 21 | struct B: Hashable { 22 | var id: String 23 | } 24 | 25 | struct C: Hashable { 26 | var id: String 27 | } 28 | 29 | @State var isPresented = false 30 | @State var path: NavigationPath = .init([A(id: "A")]) 31 | 32 | var body: some View { 33 | 34 | VStack { 35 | 36 | HStack { 37 | Button { 38 | path = .init() 39 | path.append(A(id: "A")) 40 | path.append(A(id: "B")) 41 | path.append(A(id: "C")) 42 | } label: { 43 | Text("Set") 44 | } 45 | 46 | Button { 47 | path.append(A(id: UUID().uuidString)) 48 | } label: { 49 | Text("Append") 50 | } 51 | 52 | Button { 53 | isPresented = true 54 | } label: { 55 | Text("Momentary") 56 | } 57 | 58 | } 59 | 60 | NavigationStack(path: $path) { 61 | Group { 62 | List { 63 | Text("Root") 64 | 65 | NavigationLink(value: A(id: UUID().description)) { 66 | Text("Open A") 67 | } 68 | 69 | NavigationLink(value: B(id: UUID().description)) { 70 | Text("Open B") 71 | } 72 | 73 | NavigationLink(value: C(id: UUID().description)) { 74 | Text("Open C") 75 | } 76 | 77 | NavigationLink.init { 78 | Text("Inline destination") 79 | } label: { 80 | Text("Open inline") 81 | } 82 | 83 | Button("Present") { 84 | isPresented = true 85 | } 86 | 87 | } 88 | } 89 | 90 | .navigationDestination(for: B.self) { value in 91 | Text("View for B") 92 | } 93 | .navigationDestination(for: A.self) { value in 94 | Group { 95 | 96 | StatefulPage(title: "A, \(value.id)") 97 | 98 | NavigationLink(value: C(id: UUID().description)) { 99 | Text("Open C") 100 | } 101 | NavigationLink(value: A(id: UUID().description)) { 102 | Text("Open A") 103 | } 104 | NavigationLink.init { 105 | VStack { 106 | Text("Inline destination") 107 | } 108 | } label: { 109 | Text("Open inline") 110 | } 111 | } 112 | .navigationDestination(for: A.self) { value in 113 | Text("Another view for A") 114 | } 115 | .navigationDestination(for: C.self) { value in 116 | Text("View for C") 117 | } 118 | } 119 | .navigationDestination(isPresented: $isPresented) { 120 | Text("Present") 121 | } 122 | } 123 | } 124 | .onChange(of: path) { newValue in 125 | print(newValue) 126 | } 127 | 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/BookNesting.swift: -------------------------------------------------------------------------------- 1 | 2 | import SwiftUI 3 | import SwiftUIStack 4 | 5 | struct BookNesting: View { 6 | var body: some View { 7 | 8 | VStack { 9 | HStack { 10 | Text("A") 11 | .font(.title) 12 | Spacer() 13 | } 14 | Stack(identifier: .init("A")) { 15 | 16 | Group { 17 | StackLink { 18 | VStack { 19 | Color.purple 20 | StackUnwindLink { 21 | Text("Pop") 22 | } 23 | } 24 | } label: { 25 | Text("Push") 26 | } 27 | } 28 | 29 | VStack { 30 | 31 | HStack { 32 | Text("B") 33 | .font(.title) 34 | Spacer() 35 | } 36 | 37 | Stack(identifier: .init("B")) { 38 | 39 | Group { 40 | StackLink { 41 | VStack { 42 | Color.purple 43 | StackUnwindLink { 44 | Text("Pop") 45 | } 46 | } 47 | } label: { 48 | Text("Push") 49 | } 50 | } 51 | 52 | VStack { 53 | 54 | HStack { 55 | Text("C") 56 | .font(.title) 57 | Spacer() 58 | } 59 | Stack(identifier: .init("C")) { 60 | 61 | Group { 62 | StackLink(target: .identifier(.init("B"))) { 63 | VStack { 64 | Color.purple 65 | StackUnwindLink { 66 | Text("Pop") 67 | } 68 | } 69 | } label: { 70 | Text("Push") 71 | } 72 | } 73 | 74 | } 75 | } 76 | .padding(.leading, 20) 77 | 78 | } 79 | } 80 | .padding(.leading, 20) 81 | } 82 | } 83 | .padding(20) 84 | 85 | } 86 | } 87 | 88 | struct BookNesting_Previews: PreviewProvider { 89 | static var previews: some View { 90 | BookNesting() 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/BookStack.swift: -------------------------------------------------------------------------------- 1 | import SwiftUIStack 2 | import SwiftUI 3 | import SwiftUISupport 4 | import swiftui_color 5 | 6 | extension Color { 7 | static var appGreen: Color { 8 | .init(.displayP3, hexInt: 0xced788, opacity: 1) 9 | } 10 | static var appPurple: Color { 11 | .init(.displayP3, hexInt: 0x654ee8, opacity: 1) 12 | } 13 | static var appRed: Color { 14 | .init(.displayP3, hexInt: 0xdb6358, opacity: 1) 15 | } 16 | } 17 | 18 | struct BookStack: View { 19 | 20 | @State var momentA: Bool = false 21 | @State var momentB: Bool = false 22 | 23 | @Binding var path: StackPath 24 | 25 | @State var counter: Int = 0 26 | 27 | init(path: Binding) { 28 | self._path = path 29 | } 30 | 31 | var body: some View { 32 | 33 | VStack { 34 | 35 | StackUnwindLink { 36 | Text("Back") 37 | } 38 | 39 | VStack { 40 | 41 | Text("Stack") 42 | .font(.title) 43 | .relative(vertical: .center, horizontal: .leading) 44 | 45 | Stack(path: $path) { 46 | 47 | VStack { 48 | Text("Root") 49 | 50 | StackLink(value: M()) { 51 | Text("Open A") 52 | } 53 | 54 | StackLink(value: M()) { 55 | Text("Open B") 56 | } 57 | // 58 | // StackLink(value: M()) { 59 | // Text("Open C") 60 | // } 61 | 62 | Button("Toggle Alert A") { 63 | momentA = true 64 | } 65 | 66 | Button("Toggle Alert B") { 67 | momentB = true 68 | } 69 | } 70 | .stackDestination(for: M.self) { model in 71 | ZStack { 72 | Color.appPurple 73 | 74 | VStack { 75 | StatefulPage(title: "\(model)") 76 | 77 | StackLink(value: M()) { 78 | Text("Open B") 79 | } 80 | 81 | StackUnwindLink { 82 | Text("Pop") 83 | } 84 | } 85 | } 86 | 87 | } 88 | .stackDestination(for: M.self) { model in 89 | ZStack { 90 | Color.appRed 91 | VStack { 92 | Text(String(describing: model)) 93 | 94 | StackLink(value: M()) { 95 | Text("Open A") 96 | } 97 | 98 | StackUnwindLink { 99 | Text("Pop") 100 | } 101 | } 102 | } 103 | } 104 | 105 | .stackDestination(isPresented: $momentA) { 106 | ZStack { 107 | Color.purple 108 | VStack { 109 | Text("Moment A") 110 | StackUnwindLink { 111 | Text("Pop") 112 | } 113 | } 114 | } 115 | } 116 | .stackDestination(isPresented: $momentB) { 117 | ZStack { 118 | Color.purple 119 | VStack { 120 | Text("Moment B") 121 | StackUnwindLink { 122 | Text("Pop") 123 | } 124 | } 125 | } 126 | } 127 | } 128 | .frame(height: 120) 129 | .background(Color.appGreen) 130 | } 131 | .padding(.horizontal, 20) 132 | 133 | VStack { 134 | 135 | Text("Controls") 136 | .font(.title) 137 | .relative(vertical: .center, horizontal: .leading) 138 | 139 | VStack { 140 | Button("\(counter.description)") { 141 | counter += 1 142 | } 143 | Button("Toggle Moment A") { 144 | momentA.toggle() 145 | } 146 | 147 | Button("Set 1") { 148 | path = .init() 149 | path.append(M(id: "1")) 150 | path.append(M(id: "2")) 151 | path.append(M(id: "3")) 152 | } 153 | 154 | Button("Set 2") { 155 | path = .init() 156 | path.append(M(id: "4")) 157 | path.append(M(id: "5")) 158 | path.append(M(id: "6")) 159 | } 160 | 161 | Button("Append") { 162 | path.append(M(id: "4")) 163 | } 164 | } 165 | } 166 | .padding(.horizontal, 20) 167 | 168 | VStack { 169 | 170 | Text("Path") 171 | .font(.title) 172 | .relative(vertical: .center, horizontal: .leading) 173 | 174 | } 175 | .padding(.horizontal, 20) 176 | } 177 | .background(Color(white: 0, opacity: 0.05)) 178 | 179 | } 180 | } 181 | 182 | struct BookStack_Previews: PreviewProvider { 183 | 184 | struct Wrap: View { 185 | @State var path: StackPath = .init() 186 | var body: some View { 187 | BookStack(path: $path) 188 | } 189 | } 190 | 191 | static var previews: some View { 192 | Wrap() 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/BookStackNoPath.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import SwiftUIStack 3 | 4 | struct BookStackNoPath: View { 5 | 6 | @State var momentA: Bool = false 7 | @State var momentB: Bool = false 8 | 9 | @State var counter: Int = 0 10 | 11 | var body: some View { 12 | 13 | VStack { 14 | 15 | StackUnwindLink { 16 | Text("Back") 17 | } 18 | 19 | Stack { 20 | 21 | VStack { 22 | Text("Root") 23 | 24 | StackLink(value: M()) { 25 | Text("Open A") 26 | } 27 | 28 | StackLink(value: M()) { 29 | Text("Open B") 30 | } 31 | 32 | StackLink(value: M()) { 33 | Text("Open C") 34 | } 35 | 36 | Button("Toggle Alert A") { 37 | momentA = true 38 | } 39 | 40 | Button("Toggle Alert B") { 41 | momentB = true 42 | } 43 | } 44 | .stackDestination(for: M.self) { model in 45 | ZStack { 46 | Color.red 47 | 48 | VStack { 49 | StatefulPage(title: "\(model)") 50 | 51 | StackLink(value: M()) { 52 | Text("Open B") 53 | } 54 | 55 | StackUnwindLink { 56 | Text("Pop") 57 | } 58 | } 59 | } 60 | } 61 | .stackDestination(for: M.self) { model in 62 | ZStack { 63 | Color.yellow 64 | VStack { 65 | Text(String(describing: model)) 66 | 67 | StackLink(value: M()) { 68 | Text("Open A") 69 | } 70 | 71 | StackUnwindLink { 72 | Text("Pop") 73 | } 74 | } 75 | } 76 | } 77 | .stackDestination(for: M.self) { model in 78 | ZStack { 79 | Color.purple 80 | VStack { 81 | Text(String(describing: model)) 82 | StackUnwindLink { 83 | Text("Pop") 84 | } 85 | } 86 | } 87 | } 88 | .stackDestination(isPresented: $momentA) { 89 | ZStack { 90 | Color.purple 91 | VStack { 92 | Text("Moment A") 93 | StackUnwindLink { 94 | Text("Pop") 95 | } 96 | } 97 | } 98 | } 99 | .stackDestination(isPresented: $momentB) { 100 | ZStack { 101 | Color.purple 102 | VStack { 103 | Text("Moment B") 104 | StackUnwindLink { 105 | Text("Pop") 106 | } 107 | } 108 | } 109 | } 110 | 111 | } 112 | } 113 | } 114 | } 115 | 116 | struct BookStackNoPath_Previews: PreviewProvider { 117 | static var previews: some View { 118 | BookStackNoPath() 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/BookStack_Grid.swift: -------------------------------------------------------------------------------- 1 | import SwiftUIStack 2 | import SwiftUI 3 | import SwiftUISupport 4 | 5 | @available(iOS 14, *) 6 | struct BookStack_Grid: View { 7 | 8 | @State var data: [UserData] = UserData.generateDummyData(count: 50) 9 | 10 | @Environment(\.stackUnwindContext) var unwindContext 11 | 12 | @Namespace var local 13 | 14 | var body: some View { 15 | 16 | Stack { 17 | 18 | ScrollView { 19 | 20 | LazyVStack { 21 | 22 | StackUnwindLink(target: .specific(unwindContext)) { 23 | Text("Back to Menu") 24 | } 25 | 26 | ForEach(data, id: \.id) { userData in 27 | makeUserCell(userData: userData) 28 | } 29 | } 30 | 31 | } 32 | .stackDestination(for: UserData.self) { userData in 33 | UserDetailView(userData: userData, namespace: local) 34 | } 35 | 36 | } 37 | 38 | } 39 | 40 | fileprivate func makeUserCell( 41 | userData: UserData 42 | ) -> some View { 43 | StackLink(transition: .matched(identifier: userData.id, in: local), value: userData) { 44 | VStack { 45 | HStack(spacing: 12) { 46 | Circle() 47 | .fill(Color.gray) 48 | .frame( 49 | width: 40, 50 | height: 40, 51 | alignment: .center 52 | ) 53 | .matchedGeometryEffect(id: "\(userData.id)-image", in: local) 54 | 55 | Text(userData.name) 56 | .font(.system(.body, design: .default)) 57 | .matchedGeometryEffect(id: "\(userData.id)-name", in: local) 58 | 59 | Spacer() 60 | } 61 | .padding(.horizontal, 24) 62 | .padding(.vertical, 8) 63 | .background(Color.orange) 64 | } 65 | } 66 | } 67 | 68 | struct UserDetailView: View { 69 | let userData: UserData 70 | 71 | let namespace: Namespace.ID 72 | 73 | @State var flag = false 74 | 75 | var body: some View { 76 | ZStack { 77 | 78 | Color.blue.ignoresSafeArea() 79 | 80 | VStack(spacing: 20) { 81 | 82 | StackUnwindLink { 83 | Text("Back") 84 | } 85 | 86 | Rectangle() 87 | .fill(.white) 88 | .frame(width: 60, height: 60) 89 | .rotationEffect(flag ? .degrees(0) : .degrees(360)) 90 | .animation(.linear(duration: 1).repeatForever(autoreverses: false), value: flag) 91 | .onAppear { 92 | flag = true 93 | } 94 | .matchedGeometryEffect(id: "\(userData.id)-image", in: namespace) 95 | 96 | Text("User Details") 97 | .font(.largeTitle) 98 | .fontWeight(.bold) 99 | 100 | HStack { 101 | Text("ID:") 102 | .font(.title2) 103 | .fontWeight(.bold) 104 | Spacer() 105 | Text(userData.id) 106 | .font(.title2) 107 | .foregroundColor(.gray) 108 | } 109 | 110 | HStack { 111 | Text("Name:") 112 | .font(.title2) 113 | .fontWeight(.bold) 114 | Spacer() 115 | Text(userData.name) 116 | .font(.title2) 117 | .foregroundColor(.gray) 118 | .matchedGeometryEffect(id: "\(userData.id)-name", in: namespace) 119 | } 120 | 121 | HStack { 122 | Text("Age:") 123 | .font(.title2) 124 | .fontWeight(.bold) 125 | Spacer() 126 | Text("\(userData.age)") 127 | .font(.title2) 128 | .foregroundColor(.gray) 129 | } 130 | 131 | Spacer(minLength: 0) 132 | } 133 | } 134 | 135 | } 136 | } 137 | 138 | } 139 | 140 | struct UserData: Hashable { 141 | 142 | let id: String 143 | var name: String 144 | var age: Int 145 | 146 | static func generateDummyData(count: Int = 50) -> [UserData] { 147 | let names: [String] = [ 148 | "Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace", "Hannah", "Ivan", "Jack", 149 | "Kelly", "Linda", "Mike", "Nina", "Oscar", "Paul", "Queen", "Rachel", "Steve", "Tracy", 150 | "Ursula", "Victor", "Wendy", "Xavier", "Yvonne", "Zack", 151 | ] 152 | 153 | var dummyData: [UserData] = [] 154 | 155 | for _ in 0.. ColorScheme { 278 | 279 | let i = allTypes.firstIndex(of: one)! 280 | 281 | let next = i.advanced(by: 1) 282 | 283 | guard allTypes.indices.contains(next) else { 284 | return allTypes.first! 285 | } 286 | 287 | return allTypes[next] 288 | } 289 | 290 | } 291 | 292 | 293 | 294 | struct ColorSchemePreview_Previews: PreviewProvider { 295 | 296 | struct ColorSchemePreview: View { 297 | let colorScheme: ColorScheme 298 | 299 | /* 300 | let background: Color 301 | let headline: Color 302 | let paragraph: Color 303 | let cardBackground: Color 304 | let cardHeadline: Color 305 | let cardParagraph: Color 306 | let cardTagBackground: Color 307 | let cardTagText: Color 308 | let cardHighlight: Color 309 | */ 310 | 311 | var body: some View { 312 | HStack { 313 | RoundedRectangle(cornerRadius: 10) 314 | .fill(colorScheme.background) 315 | .frame(height: 60) 316 | RoundedRectangle(cornerRadius: 10) 317 | .fill(colorScheme.headline) 318 | .frame(height: 60) 319 | RoundedRectangle(cornerRadius: 10) 320 | .fill(colorScheme.paragraph) 321 | .frame(height: 60) 322 | RoundedRectangle(cornerRadius: 10) 323 | .fill(colorScheme.cardBackground) 324 | .frame(height: 60) 325 | RoundedRectangle(cornerRadius: 10) 326 | .fill(colorScheme.cardHeadline) 327 | .frame(height: 60) 328 | RoundedRectangle(cornerRadius: 10) 329 | .fill(colorScheme.cardParagraph) 330 | .frame(height: 60) 331 | RoundedRectangle(cornerRadius: 10) 332 | .fill(colorScheme.cardTagBackground) 333 | .frame(height: 60) 334 | 335 | RoundedRectangle(cornerRadius: 10) 336 | .fill(colorScheme.cardTagText) 337 | .frame(height: 60) 338 | RoundedRectangle(cornerRadius: 10) 339 | .fill(colorScheme.cardHighlight) 340 | .frame(height: 60) 341 | } 342 | .padding() 343 | } 344 | } 345 | 346 | static var previews: some View { 347 | ScrollView { 348 | Group { 349 | ColorSchemePreview(colorScheme: ColorScheme.type1) 350 | ColorSchemePreview(colorScheme: ColorScheme.type2) 351 | ColorSchemePreview(colorScheme: ColorScheme.type3) 352 | ColorSchemePreview(colorScheme: ColorScheme.type4) 353 | ColorSchemePreview(colorScheme: ColorScheme.type5) 354 | ColorSchemePreview(colorScheme: ColorScheme.type6) 355 | ColorSchemePreview(colorScheme: ColorScheme.type7) 356 | ColorSchemePreview(colorScheme: ColorScheme.type8) 357 | } 358 | Group { 359 | ColorSchemePreview(colorScheme: ColorScheme.type9) 360 | ColorSchemePreview(colorScheme: ColorScheme.type10) 361 | ColorSchemePreview(colorScheme: ColorScheme.type11) 362 | ColorSchemePreview(colorScheme: ColorScheme.type12) 363 | ColorSchemePreview(colorScheme: ColorScheme.type13) 364 | ColorSchemePreview(colorScheme: ColorScheme.type14) 365 | ColorSchemePreview(colorScheme: ColorScheme.type15) 366 | ColorSchemePreview(colorScheme: ColorScheme.type16) 367 | ColorSchemePreview(colorScheme: ColorScheme.type17) 368 | } 369 | } 370 | .background(Color.gray) 371 | .previewLayout(.sizeThatFits) 372 | .padding() 373 | } 374 | } 375 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // StackDemoApp 4 | // 5 | // Created by Muukii on 2022/09/29. 6 | // 7 | 8 | import SwiftUIStack 9 | import SwiftUI 10 | 11 | struct ContentView: View { 12 | 13 | @State var path1 = StackPath() 14 | @State var path2 = StackPath([M.init()]) 15 | @State var path3 = StackPath() 16 | 17 | var body: some View { 18 | Stack(identifier: .init("root")) { 19 | 20 | Button("Reset") { 21 | path2 = .init([M.init()]) 22 | } 23 | 24 | Form { 25 | 26 | Section { 27 | 28 | StackLink { 29 | BookStack(path: $path1) 30 | .background(Color.white) 31 | } label: { 32 | Text("Stack") 33 | } 34 | 35 | StackLink { 36 | BookFullScreenStack() 37 | } label: { 38 | Text("Stack fullscreen") 39 | } 40 | 41 | StackLink { 42 | BookStack_Grid() 43 | .background(Color.white) 44 | } label: { 45 | Text("Stack - Grid") 46 | } 47 | 48 | StackLink { 49 | BookStack(path: $path2) 50 | .background(Color.white) 51 | } label: { 52 | Text("Stack restore-path") 53 | } 54 | StackLink { 55 | BookStackNoPath() 56 | .background(Color.white) 57 | } label: { 58 | Text("Stack no path") 59 | } 60 | 61 | } header: { 62 | Text("Stack") 63 | } 64 | 65 | Section { 66 | 67 | StackLink(transition: .basic(transition: .move(edge: .bottom).animation(.smoothSpring))) { 68 | ZStack { 69 | Color.white 70 | .ignoresSafeArea() 71 | StackUnwindLink { 72 | Text("Pop") 73 | } 74 | } 75 | } label: { 76 | Text("Stack") 77 | } 78 | 79 | } header: { 80 | Text("Stack transition") 81 | } 82 | 83 | Section { 84 | 85 | StackLink { 86 | BookNavigationStack() 87 | } label: { 88 | Text("NavigationStack") 89 | } 90 | 91 | StackLink { 92 | BookMatchedShape() 93 | } label: { 94 | Text("Matched Shape") 95 | } 96 | 97 | StackLink { 98 | IGAppRoot() 99 | } label: { 100 | Text("Instagram") 101 | } 102 | } header: { 103 | Text("Playgrounds") 104 | } 105 | 106 | Section { 107 | 108 | StackLink { 109 | BookNesting() 110 | .background(Color.white) 111 | } label: { 112 | Text("Nesting") 113 | } 114 | 115 | TransitionView() 116 | } header: { 117 | Text("FluidStack") 118 | } 119 | 120 | } 121 | 122 | } 123 | } 124 | } 125 | 126 | struct TransitionView: View { 127 | 128 | struct ViewBox: View, Identifiable { 129 | 130 | var id: String { 131 | model.id 132 | } 133 | 134 | var model: M 135 | var view: AnyView 136 | 137 | var body: some View { 138 | view 139 | } 140 | } 141 | 142 | @State var items: [ViewBox] = [] 143 | 144 | var body: some View { 145 | VStack { 146 | Button("+") { 147 | withAnimation { 148 | items.append( 149 | .init( 150 | model: .init(), 151 | view: .init( 152 | Circle() 153 | .opacity(0.2) 154 | .frame(width: 30, height: 30) 155 | ) 156 | ) 157 | ) 158 | } 159 | } 160 | Button("-") { 161 | withAnimation { 162 | _ = items.removeLast() 163 | } 164 | } 165 | ZStack { 166 | ForEach(items) { item in 167 | item 168 | .transition(.scale) 169 | } 170 | } 171 | } 172 | } 173 | } 174 | 175 | struct ContentView_Previews: PreviewProvider { 176 | static var previews: some View { 177 | ContentView() 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Instagram/IGAppRoot.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct IGAppRoot: View { 4 | 5 | var body: some View { 6 | IGTabView() 7 | } 8 | } 9 | 10 | enum IGAppRoot_Previews: PreviewProvider { 11 | 12 | static var previews: some View { 13 | IGAppRoot() 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Instagram/IGTabView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct IGTabView: View { 4 | var body: some View { 5 | TabView { 6 | IGHomeView() 7 | .tabItem { 8 | Image(systemName: "house.fill") 9 | Text("Home") 10 | } 11 | IGSearchView() 12 | .tabItem { 13 | Image(systemName: "magnifyingglass") 14 | Text("Search") 15 | } 16 | IGAddPostView() 17 | .tabItem { 18 | Image(systemName: "plus.square") 19 | Text("Add Post") 20 | } 21 | IGNotificationsView() 22 | .tabItem { 23 | Image(systemName: "heart.fill") 24 | Text("Notifications") 25 | } 26 | IGProfileView() 27 | .tabItem { 28 | Image(systemName: "person.fill") 29 | Text("Profile") 30 | } 31 | } 32 | } 33 | } 34 | 35 | struct IGHomeView: View { 36 | var body: some View { 37 | Text("Home") 38 | } 39 | } 40 | 41 | struct IGSearchView: View { 42 | var body: some View { 43 | Text("Search") 44 | } 45 | } 46 | 47 | struct IGAddPostView: View { 48 | var body: some View { 49 | Text("Add Post") 50 | } 51 | } 52 | 53 | struct IGNotificationsView: View { 54 | var body: some View { 55 | Text("Notifications") 56 | } 57 | } 58 | 59 | struct IGProfileView: View { 60 | let columns: [GridItem] = Array(repeating: .init(.flexible(), spacing: 2), count: 3) 61 | 62 | var body: some View { 63 | ScrollView { 64 | VStack(alignment: .leading) { 65 | // Profile information and settings button can be added here 66 | LazyVGrid(columns: columns, spacing: 2) { 67 | ForEach(0..<30, id: \.self) { _ in 68 | Rectangle() 69 | .foregroundColor(Color.gray) 70 | .aspectRatio(1, contentMode: .fit) 71 | } 72 | } 73 | .padding(2) 74 | } 75 | } 76 | } 77 | } 78 | 79 | struct IGPhotoDetailView: View { 80 | @Binding var isPresented: Bool 81 | 82 | var body: some View { 83 | ZStack { 84 | Color.black.edgesIgnoringSafeArea(.all) 85 | RoundedRectangle(cornerRadius: 10) 86 | .fill(Color.gray) 87 | .frame(width: 300, height: 300) 88 | VStack { 89 | Spacer() 90 | HStack { 91 | Spacer() 92 | Button(action: { 93 | isPresented = false 94 | }, label: { 95 | Image(systemName: "xmark.circle.fill") 96 | .resizable() 97 | .foregroundColor(.white) 98 | .frame(width: 30, height: 30) 99 | }) 100 | } 101 | Spacer() 102 | } 103 | .padding() 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Launch Screen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Model.swift: -------------------------------------------------------------------------------- 1 | 2 | struct M: Hashable, Identifiable { 3 | var id: String = UUID().uuidString 4 | } 5 | 6 | enum A {} 7 | enum B {} 8 | enum C {} 9 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/StatefulPage.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct StatefulPage: View { 4 | 5 | private let title: String 6 | 7 | @State var isOn: Bool = false 8 | 9 | init(title: String) { 10 | self.title = title 11 | } 12 | 13 | var body: some View { 14 | VStack { 15 | Text(title) 16 | Toggle(isOn: $isOn) { 17 | Text("Toggle") 18 | } 19 | } 20 | } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /StackApp/StackDemoApp/Views.swift: -------------------------------------------------------------------------------- 1 | import SwiftUIStack 2 | import SwiftUI 3 | 4 | struct ModelView: View { 5 | 6 | private let representation: String 7 | private let color: Color 8 | private let content: Content 9 | 10 | init( 11 | model: Model, 12 | color: Color, 13 | @ViewBuilder content: () -> Content 14 | ) { 15 | self.representation = String(describing: model) 16 | self.color = color 17 | self.content = content() 18 | } 19 | 20 | @State var isOn = false 21 | @State var count = 0 22 | 23 | var body: some View { 24 | 25 | VStack { 26 | 27 | Text(representation) 28 | .foregroundColor(.white) 29 | .blendMode(.difference) 30 | 31 | Toggle(isOn: $isOn) { 32 | Text("Toggle") 33 | } 34 | 35 | Text("\(count.description)") 36 | 37 | Button("Up") { 38 | count += 1 39 | } 40 | 41 | content 42 | 43 | } 44 | .padding(24) 45 | .background(color) 46 | 47 | } 48 | } 49 | 50 | struct ModelView_Previews: PreviewProvider { 51 | static var previews: some View { 52 | ModelView( 53 | model: M.init(), 54 | color: .purple, 55 | content: { 56 | EmptyView() 57 | } 58 | ) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /StackApp/StackDemoAppTests/StackDemoAppTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StackDemoAppTests.swift 3 | // StackDemoAppTests 4 | // 5 | // Created by Muukii on 2022/09/29. 6 | // 7 | 8 | import XCTest 9 | @testable import StackDemoApp 10 | 11 | final class StackDemoAppTests: XCTestCase { 12 | 13 | override func setUpWithError() throws { 14 | // Put setup code here. This method is called before the invocation of each test method in the class. 15 | } 16 | 17 | override func tearDownWithError() throws { 18 | // Put teardown code here. This method is called after the invocation of each test method in the class. 19 | } 20 | 21 | func testExample() throws { 22 | // This is an example of a functional test case. 23 | // Use XCTAssert and related functions to verify your tests produce the correct results. 24 | // Any test you write for XCTest can be annotated as throws and async. 25 | // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. 26 | // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. 27 | } 28 | 29 | func testPerformanceExample() throws { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /StackApp/StackDemoAppUITests/StackDemoAppUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StackDemoAppUITests.swift 3 | // StackDemoAppUITests 4 | // 5 | // Created by Muukii on 2022/09/29. 6 | // 7 | 8 | import XCTest 9 | 10 | final class StackDemoAppUITests: XCTestCase { 11 | 12 | override func setUpWithError() throws { 13 | // Put setup code here. This method is called before the invocation of each test method in the class. 14 | 15 | // In UI tests it is usually best to stop immediately when a failure occurs. 16 | continueAfterFailure = false 17 | 18 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 19 | } 20 | 21 | override func tearDownWithError() throws { 22 | // Put teardown code here. This method is called after the invocation of each test method in the class. 23 | } 24 | 25 | func testExample() throws { 26 | // UI tests must launch the application that they test. 27 | let app = XCUIApplication() 28 | app.launch() 29 | 30 | // Use XCTAssert and related functions to verify your tests produce the correct results. 31 | } 32 | 33 | func testLaunchPerformance() throws { 34 | if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { 35 | // This measures how long it takes to launch your application. 36 | measure(metrics: [XCTApplicationLaunchMetric()]) { 37 | XCUIApplication().launch() 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /StackApp/StackDemoAppUITests/StackDemoAppUITestsLaunchTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StackDemoAppUITestsLaunchTests.swift 3 | // StackDemoAppUITests 4 | // 5 | // Created by Muukii on 2022/09/29. 6 | // 7 | 8 | import XCTest 9 | 10 | final class StackDemoAppUITestsLaunchTests: XCTestCase { 11 | 12 | override class var runsForEachTargetApplicationUIConfiguration: Bool { 13 | true 14 | } 15 | 16 | override func setUpWithError() throws { 17 | continueAfterFailure = false 18 | } 19 | 20 | func testLaunch() throws { 21 | let app = XCUIApplication() 22 | app.launch() 23 | 24 | // Insert steps here to perform after app launch but before taking a screenshot, 25 | // such as logging into a test account or navigating somewhere in the app 26 | 27 | let attachment = XCTAttachment(screenshot: app.screenshot()) 28 | attachment.name = "Launch Screen" 29 | attachment.lifetime = .keepAlways 30 | add(attachment) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Tests/SwiftUIStackTests/Model.swift: -------------------------------------------------------------------------------- 1 | 2 | import Foundation 3 | 4 | struct M: Hashable, Identifiable { 5 | var id: String = UUID().uuidString 6 | } 7 | 8 | enum A {} 9 | enum B {} 10 | enum C {} 11 | -------------------------------------------------------------------------------- /Tests/SwiftUIStackTests/StackTests.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import ViewInspector 3 | import XCTest 4 | 5 | @testable import SwiftUIStack 6 | 7 | final class StackTests: XCTestCase { 8 | 9 | @MainActor 10 | func test_stack_displays_root() throws { 11 | 12 | let stack = Stack { 13 | Text("").id("Root") 14 | } 15 | 16 | _ = try stack.inspect().find(viewWithId: "Root") 17 | } 18 | 19 | @MainActor 20 | func test_stack_push_destination() throws { 21 | // TODO: 22 | 23 | } 24 | } 25 | 26 | --------------------------------------------------------------------------------