├── .gitignore ├── README.md └── SwiftUINavigation ├── SwiftUINavigation.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── SwiftUINavigation ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── ContentView.swift ├── Info.plist ├── MyApp.swift ├── Preview Content └── Preview Assets.xcassets │ └── Contents.json ├── container ├── ContainerModel.swift ├── ContainerView.swift ├── IModel.swift ├── IModelView.swift ├── LazyView.swift └── LoaderView.swift ├── extension ├── View+Any.swift └── View+Navigation.swift ├── navigation ├── NavigationItemContainer.swift ├── NavigationStack.swift ├── NavigationViewContainer.swift ├── NavigationViewModel.swift └── Screen.swift ├── navigator ├── IScreenView.swift ├── Navigator.swift └── config │ └── ModuleConfig.swift └── old ├── AppDelegate.swift └── SceneDelegate.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swiftui_navigation 2 | 3 | Sample solution for navigation in swiftUI app 4 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1DA5C8A2253B36D7000C2FB8 /* MyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA5C8A1253B36D7000C2FB8 /* MyApp.swift */; }; 11 | 1DA5C8BC253B3A46000C2FB8 /* ModuleConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA5C8B9253B3A46000C2FB8 /* ModuleConfig.swift */; }; 12 | 1DA5C8BD253B3A46000C2FB8 /* IScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA5C8BA253B3A46000C2FB8 /* IScreenView.swift */; }; 13 | 1DA5C8BE253B3A46000C2FB8 /* Navigator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA5C8BB253B3A46000C2FB8 /* Navigator.swift */; }; 14 | 1DD1AC5D25053A850013CA37 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC5C25053A850013CA37 /* AppDelegate.swift */; }; 15 | 1DD1AC5F25053A850013CA37 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC5E25053A850013CA37 /* SceneDelegate.swift */; }; 16 | 1DD1AC6125053A850013CA37 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC6025053A850013CA37 /* ContentView.swift */; }; 17 | 1DD1AC6325053A890013CA37 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1DD1AC6225053A890013CA37 /* Assets.xcassets */; }; 18 | 1DD1AC6625053A890013CA37 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1DD1AC6525053A890013CA37 /* Preview Assets.xcassets */; }; 19 | 1DD1AC6925053A890013CA37 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1DD1AC6725053A890013CA37 /* LaunchScreen.storyboard */; }; 20 | 1DD1AC7225053B3F0013CA37 /* View+Any.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC7125053B3F0013CA37 /* View+Any.swift */; }; 21 | 1DD1AC7425053C580013CA37 /* ContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC7325053C580013CA37 /* ContainerView.swift */; }; 22 | 1DD1AC7625053C7A0013CA37 /* ContainerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC7525053C7A0013CA37 /* ContainerModel.swift */; }; 23 | 1DD1AC7825053C9E0013CA37 /* IModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC7725053C9E0013CA37 /* IModel.swift */; }; 24 | 1DD1AC7A25053CBC0013CA37 /* IModelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC7925053CBC0013CA37 /* IModelView.swift */; }; 25 | 1DD1AC7C25053CD70013CA37 /* LazyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC7B25053CD70013CA37 /* LazyView.swift */; }; 26 | 1DD1AC80250545900013CA37 /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC7F250545900013CA37 /* Screen.swift */; }; 27 | 1DD1AC82250546A10013CA37 /* NavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC81250546A10013CA37 /* NavigationViewModel.swift */; }; 28 | 1DD1AC842505479F0013CA37 /* NavigationViewContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC832505479F0013CA37 /* NavigationViewContainer.swift */; }; 29 | 1DD1AC862505DA060013CA37 /* View+Navigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DD1AC852505DA060013CA37 /* View+Navigation.swift */; }; 30 | 1DF6C99325053D4600AA3F99 /* LoaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF6C99225053D4600AA3F99 /* LoaderView.swift */; }; 31 | 1DF6C99525053DC800AA3F99 /* NavigationStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF6C99425053DC800AA3F99 /* NavigationStack.swift */; }; 32 | 1DF6C9972505538A00AA3F99 /* NavigationItemContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF6C9962505538A00AA3F99 /* NavigationItemContainer.swift */; }; 33 | /* End PBXBuildFile section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 1DA5C8A1253B36D7000C2FB8 /* MyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyApp.swift; sourceTree = ""; }; 37 | 1DA5C8B9253B3A46000C2FB8 /* ModuleConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModuleConfig.swift; sourceTree = ""; }; 38 | 1DA5C8BA253B3A46000C2FB8 /* IScreenView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IScreenView.swift; sourceTree = ""; }; 39 | 1DA5C8BB253B3A46000C2FB8 /* Navigator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Navigator.swift; sourceTree = ""; }; 40 | 1DD1AC5925053A850013CA37 /* SwiftUINavigation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUINavigation.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 1DD1AC5C25053A850013CA37 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 42 | 1DD1AC5E25053A850013CA37 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 43 | 1DD1AC6025053A850013CA37 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 44 | 1DD1AC6225053A890013CA37 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 45 | 1DD1AC6525053A890013CA37 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 46 | 1DD1AC6825053A890013CA37 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 47 | 1DD1AC6A25053A890013CA37 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | 1DD1AC7125053B3F0013CA37 /* View+Any.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Any.swift"; sourceTree = ""; }; 49 | 1DD1AC7325053C580013CA37 /* ContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerView.swift; sourceTree = ""; }; 50 | 1DD1AC7525053C7A0013CA37 /* ContainerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerModel.swift; sourceTree = ""; }; 51 | 1DD1AC7725053C9E0013CA37 /* IModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IModel.swift; sourceTree = ""; }; 52 | 1DD1AC7925053CBC0013CA37 /* IModelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IModelView.swift; sourceTree = ""; }; 53 | 1DD1AC7B25053CD70013CA37 /* LazyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyView.swift; sourceTree = ""; }; 54 | 1DD1AC7F250545900013CA37 /* Screen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Screen.swift; sourceTree = ""; }; 55 | 1DD1AC81250546A10013CA37 /* NavigationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewModel.swift; sourceTree = ""; }; 56 | 1DD1AC832505479F0013CA37 /* NavigationViewContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewContainer.swift; sourceTree = ""; }; 57 | 1DD1AC852505DA060013CA37 /* View+Navigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Navigation.swift"; sourceTree = ""; }; 58 | 1DF6C99225053D4600AA3F99 /* LoaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoaderView.swift; sourceTree = ""; }; 59 | 1DF6C99425053DC800AA3F99 /* NavigationStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationStack.swift; sourceTree = ""; }; 60 | 1DF6C9962505538A00AA3F99 /* NavigationItemContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationItemContainer.swift; sourceTree = ""; }; 61 | /* End PBXFileReference section */ 62 | 63 | /* Begin PBXFrameworksBuildPhase section */ 64 | 1DD1AC5625053A850013CA37 /* Frameworks */ = { 65 | isa = PBXFrameworksBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | /* End PBXFrameworksBuildPhase section */ 72 | 73 | /* Begin PBXGroup section */ 74 | 1DA5C8A5253B37A6000C2FB8 /* old */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 1DD1AC5C25053A850013CA37 /* AppDelegate.swift */, 78 | 1DD1AC5E25053A850013CA37 /* SceneDelegate.swift */, 79 | ); 80 | path = old; 81 | sourceTree = ""; 82 | }; 83 | 1DA5C8A6253B37DE000C2FB8 /* container */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 1DD1AC7325053C580013CA37 /* ContainerView.swift */, 87 | 1DD1AC7525053C7A0013CA37 /* ContainerModel.swift */, 88 | 1DD1AC7725053C9E0013CA37 /* IModel.swift */, 89 | 1DD1AC7925053CBC0013CA37 /* IModelView.swift */, 90 | 1DD1AC7B25053CD70013CA37 /* LazyView.swift */, 91 | 1DF6C99225053D4600AA3F99 /* LoaderView.swift */, 92 | ); 93 | path = container; 94 | sourceTree = ""; 95 | }; 96 | 1DA5C8A8253B3840000C2FB8 /* navigation */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 1DF6C99425053DC800AA3F99 /* NavigationStack.swift */, 100 | 1DD1AC7F250545900013CA37 /* Screen.swift */, 101 | 1DD1AC81250546A10013CA37 /* NavigationViewModel.swift */, 102 | 1DD1AC832505479F0013CA37 /* NavigationViewContainer.swift */, 103 | 1DF6C9962505538A00AA3F99 /* NavigationItemContainer.swift */, 104 | ); 105 | path = navigation; 106 | sourceTree = ""; 107 | }; 108 | 1DA5C8B7253B3A46000C2FB8 /* navigator */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 1DA5C8B8253B3A46000C2FB8 /* config */, 112 | 1DA5C8BA253B3A46000C2FB8 /* IScreenView.swift */, 113 | 1DA5C8BB253B3A46000C2FB8 /* Navigator.swift */, 114 | ); 115 | path = navigator; 116 | sourceTree = ""; 117 | }; 118 | 1DA5C8B8253B3A46000C2FB8 /* config */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 1DA5C8B9253B3A46000C2FB8 /* ModuleConfig.swift */, 122 | ); 123 | path = config; 124 | sourceTree = ""; 125 | }; 126 | 1DD1AC5025053A850013CA37 = { 127 | isa = PBXGroup; 128 | children = ( 129 | 1DD1AC5B25053A850013CA37 /* SwiftUINavigation */, 130 | 1DD1AC5A25053A850013CA37 /* Products */, 131 | ); 132 | sourceTree = ""; 133 | }; 134 | 1DD1AC5A25053A850013CA37 /* Products */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | 1DD1AC5925053A850013CA37 /* SwiftUINavigation.app */, 138 | ); 139 | name = Products; 140 | sourceTree = ""; 141 | }; 142 | 1DD1AC5B25053A850013CA37 /* SwiftUINavigation */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 1DA5C8B7253B3A46000C2FB8 /* navigator */, 146 | 1DA5C8A8253B3840000C2FB8 /* navigation */, 147 | 1DA5C8A6253B37DE000C2FB8 /* container */, 148 | 1DA5C8A5253B37A6000C2FB8 /* old */, 149 | 1DD1AC7025053B290013CA37 /* extension */, 150 | 1DD1AC6025053A850013CA37 /* ContentView.swift */, 151 | 1DA5C8A1253B36D7000C2FB8 /* MyApp.swift */, 152 | 1DD1AC6225053A890013CA37 /* Assets.xcassets */, 153 | 1DD1AC6725053A890013CA37 /* LaunchScreen.storyboard */, 154 | 1DD1AC6A25053A890013CA37 /* Info.plist */, 155 | 1DD1AC6425053A890013CA37 /* Preview Content */, 156 | ); 157 | path = SwiftUINavigation; 158 | sourceTree = ""; 159 | }; 160 | 1DD1AC6425053A890013CA37 /* Preview Content */ = { 161 | isa = PBXGroup; 162 | children = ( 163 | 1DD1AC6525053A890013CA37 /* Preview Assets.xcassets */, 164 | ); 165 | path = "Preview Content"; 166 | sourceTree = ""; 167 | }; 168 | 1DD1AC7025053B290013CA37 /* extension */ = { 169 | isa = PBXGroup; 170 | children = ( 171 | 1DD1AC852505DA060013CA37 /* View+Navigation.swift */, 172 | 1DD1AC7125053B3F0013CA37 /* View+Any.swift */, 173 | ); 174 | path = extension; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXGroup section */ 178 | 179 | /* Begin PBXNativeTarget section */ 180 | 1DD1AC5825053A850013CA37 /* SwiftUINavigation */ = { 181 | isa = PBXNativeTarget; 182 | buildConfigurationList = 1DD1AC6D25053A890013CA37 /* Build configuration list for PBXNativeTarget "SwiftUINavigation" */; 183 | buildPhases = ( 184 | 1DD1AC5525053A850013CA37 /* Sources */, 185 | 1DD1AC5625053A850013CA37 /* Frameworks */, 186 | 1DD1AC5725053A850013CA37 /* Resources */, 187 | ); 188 | buildRules = ( 189 | ); 190 | dependencies = ( 191 | ); 192 | name = SwiftUINavigation; 193 | productName = SwiftUINavigation; 194 | productReference = 1DD1AC5925053A850013CA37 /* SwiftUINavigation.app */; 195 | productType = "com.apple.product-type.application"; 196 | }; 197 | /* End PBXNativeTarget section */ 198 | 199 | /* Begin PBXProject section */ 200 | 1DD1AC5125053A850013CA37 /* Project object */ = { 201 | isa = PBXProject; 202 | attributes = { 203 | LastSwiftUpdateCheck = 1150; 204 | LastUpgradeCheck = 1150; 205 | ORGANIZATIONNAME = "Anna Zharkova"; 206 | TargetAttributes = { 207 | 1DD1AC5825053A850013CA37 = { 208 | CreatedOnToolsVersion = 11.5; 209 | }; 210 | }; 211 | }; 212 | buildConfigurationList = 1DD1AC5425053A850013CA37 /* Build configuration list for PBXProject "SwiftUINavigation" */; 213 | compatibilityVersion = "Xcode 9.3"; 214 | developmentRegion = en; 215 | hasScannedForEncodings = 0; 216 | knownRegions = ( 217 | en, 218 | Base, 219 | ); 220 | mainGroup = 1DD1AC5025053A850013CA37; 221 | productRefGroup = 1DD1AC5A25053A850013CA37 /* Products */; 222 | projectDirPath = ""; 223 | projectRoot = ""; 224 | targets = ( 225 | 1DD1AC5825053A850013CA37 /* SwiftUINavigation */, 226 | ); 227 | }; 228 | /* End PBXProject section */ 229 | 230 | /* Begin PBXResourcesBuildPhase section */ 231 | 1DD1AC5725053A850013CA37 /* Resources */ = { 232 | isa = PBXResourcesBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | 1DD1AC6925053A890013CA37 /* LaunchScreen.storyboard in Resources */, 236 | 1DD1AC6625053A890013CA37 /* Preview Assets.xcassets in Resources */, 237 | 1DD1AC6325053A890013CA37 /* Assets.xcassets in Resources */, 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | /* End PBXResourcesBuildPhase section */ 242 | 243 | /* Begin PBXSourcesBuildPhase section */ 244 | 1DD1AC5525053A850013CA37 /* Sources */ = { 245 | isa = PBXSourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 1DF6C99525053DC800AA3F99 /* NavigationStack.swift in Sources */, 249 | 1DA5C8BE253B3A46000C2FB8 /* Navigator.swift in Sources */, 250 | 1DD1AC7A25053CBC0013CA37 /* IModelView.swift in Sources */, 251 | 1DD1AC7425053C580013CA37 /* ContainerView.swift in Sources */, 252 | 1DD1AC80250545900013CA37 /* Screen.swift in Sources */, 253 | 1DD1AC842505479F0013CA37 /* NavigationViewContainer.swift in Sources */, 254 | 1DD1AC862505DA060013CA37 /* View+Navigation.swift in Sources */, 255 | 1DA5C8A2253B36D7000C2FB8 /* MyApp.swift in Sources */, 256 | 1DD1AC7625053C7A0013CA37 /* ContainerModel.swift in Sources */, 257 | 1DD1AC5D25053A850013CA37 /* AppDelegate.swift in Sources */, 258 | 1DD1AC5F25053A850013CA37 /* SceneDelegate.swift in Sources */, 259 | 1DA5C8BD253B3A46000C2FB8 /* IScreenView.swift in Sources */, 260 | 1DD1AC7825053C9E0013CA37 /* IModel.swift in Sources */, 261 | 1DF6C9972505538A00AA3F99 /* NavigationItemContainer.swift in Sources */, 262 | 1DD1AC7C25053CD70013CA37 /* LazyView.swift in Sources */, 263 | 1DF6C99325053D4600AA3F99 /* LoaderView.swift in Sources */, 264 | 1DD1AC6125053A850013CA37 /* ContentView.swift in Sources */, 265 | 1DA5C8BC253B3A46000C2FB8 /* ModuleConfig.swift in Sources */, 266 | 1DD1AC7225053B3F0013CA37 /* View+Any.swift in Sources */, 267 | 1DD1AC82250546A10013CA37 /* NavigationViewModel.swift in Sources */, 268 | ); 269 | runOnlyForDeploymentPostprocessing = 0; 270 | }; 271 | /* End PBXSourcesBuildPhase section */ 272 | 273 | /* Begin PBXVariantGroup section */ 274 | 1DD1AC6725053A890013CA37 /* LaunchScreen.storyboard */ = { 275 | isa = PBXVariantGroup; 276 | children = ( 277 | 1DD1AC6825053A890013CA37 /* Base */, 278 | ); 279 | name = LaunchScreen.storyboard; 280 | sourceTree = ""; 281 | }; 282 | /* End PBXVariantGroup section */ 283 | 284 | /* Begin XCBuildConfiguration section */ 285 | 1DD1AC6B25053A890013CA37 /* Debug */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_ANALYZER_NONNULL = YES; 290 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 291 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 292 | CLANG_CXX_LIBRARY = "libc++"; 293 | CLANG_ENABLE_MODULES = YES; 294 | CLANG_ENABLE_OBJC_ARC = YES; 295 | CLANG_ENABLE_OBJC_WEAK = YES; 296 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 297 | CLANG_WARN_BOOL_CONVERSION = YES; 298 | CLANG_WARN_COMMA = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 301 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 302 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 303 | CLANG_WARN_EMPTY_BODY = YES; 304 | CLANG_WARN_ENUM_CONVERSION = YES; 305 | CLANG_WARN_INFINITE_RECURSION = YES; 306 | CLANG_WARN_INT_CONVERSION = YES; 307 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 308 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 309 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 310 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 311 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 312 | CLANG_WARN_STRICT_PROTOTYPES = YES; 313 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 314 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 315 | CLANG_WARN_UNREACHABLE_CODE = YES; 316 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 317 | COPY_PHASE_STRIP = NO; 318 | DEBUG_INFORMATION_FORMAT = dwarf; 319 | ENABLE_STRICT_OBJC_MSGSEND = YES; 320 | ENABLE_TESTABILITY = YES; 321 | GCC_C_LANGUAGE_STANDARD = gnu11; 322 | GCC_DYNAMIC_NO_PIC = NO; 323 | GCC_NO_COMMON_BLOCKS = YES; 324 | GCC_OPTIMIZATION_LEVEL = 0; 325 | GCC_PREPROCESSOR_DEFINITIONS = ( 326 | "DEBUG=1", 327 | "$(inherited)", 328 | ); 329 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 330 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 331 | GCC_WARN_UNDECLARED_SELECTOR = YES; 332 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 333 | GCC_WARN_UNUSED_FUNCTION = YES; 334 | GCC_WARN_UNUSED_VARIABLE = YES; 335 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 336 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 337 | MTL_FAST_MATH = YES; 338 | ONLY_ACTIVE_ARCH = YES; 339 | SDKROOT = iphoneos; 340 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 341 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 342 | }; 343 | name = Debug; 344 | }; 345 | 1DD1AC6C25053A890013CA37 /* Release */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ALWAYS_SEARCH_USER_PATHS = NO; 349 | CLANG_ANALYZER_NONNULL = YES; 350 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 351 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 352 | CLANG_CXX_LIBRARY = "libc++"; 353 | CLANG_ENABLE_MODULES = YES; 354 | CLANG_ENABLE_OBJC_ARC = YES; 355 | CLANG_ENABLE_OBJC_WEAK = YES; 356 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 357 | CLANG_WARN_BOOL_CONVERSION = YES; 358 | CLANG_WARN_COMMA = YES; 359 | CLANG_WARN_CONSTANT_CONVERSION = YES; 360 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 361 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 362 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 363 | CLANG_WARN_EMPTY_BODY = YES; 364 | CLANG_WARN_ENUM_CONVERSION = YES; 365 | CLANG_WARN_INFINITE_RECURSION = YES; 366 | CLANG_WARN_INT_CONVERSION = YES; 367 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 368 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 369 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 370 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 371 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 372 | CLANG_WARN_STRICT_PROTOTYPES = YES; 373 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 374 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 375 | CLANG_WARN_UNREACHABLE_CODE = YES; 376 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 377 | COPY_PHASE_STRIP = NO; 378 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 379 | ENABLE_NS_ASSERTIONS = NO; 380 | ENABLE_STRICT_OBJC_MSGSEND = YES; 381 | GCC_C_LANGUAGE_STANDARD = gnu11; 382 | GCC_NO_COMMON_BLOCKS = YES; 383 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 384 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 385 | GCC_WARN_UNDECLARED_SELECTOR = YES; 386 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 387 | GCC_WARN_UNUSED_FUNCTION = YES; 388 | GCC_WARN_UNUSED_VARIABLE = YES; 389 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 390 | MTL_ENABLE_DEBUG_INFO = NO; 391 | MTL_FAST_MATH = YES; 392 | SDKROOT = iphoneos; 393 | SWIFT_COMPILATION_MODE = wholemodule; 394 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 395 | VALIDATE_PRODUCT = YES; 396 | }; 397 | name = Release; 398 | }; 399 | 1DD1AC6E25053A890013CA37 /* Debug */ = { 400 | isa = XCBuildConfiguration; 401 | buildSettings = { 402 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 403 | CODE_SIGN_STYLE = Automatic; 404 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUINavigation/Preview Content\""; 405 | DEVELOPMENT_TEAM = 7848QT82M4; 406 | ENABLE_PREVIEWS = YES; 407 | INFOPLIST_FILE = SwiftUINavigation/Info.plist; 408 | LD_RUNPATH_SEARCH_PATHS = ( 409 | "$(inherited)", 410 | "@executable_path/Frameworks", 411 | ); 412 | PRODUCT_BUNDLE_IDENTIFIER = com.azharkova.SwiftUINavigation; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | SWIFT_VERSION = 5.0; 415 | TARGETED_DEVICE_FAMILY = "1,2"; 416 | }; 417 | name = Debug; 418 | }; 419 | 1DD1AC6F25053A890013CA37 /* Release */ = { 420 | isa = XCBuildConfiguration; 421 | buildSettings = { 422 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 423 | CODE_SIGN_STYLE = Automatic; 424 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUINavigation/Preview Content\""; 425 | DEVELOPMENT_TEAM = 7848QT82M4; 426 | ENABLE_PREVIEWS = YES; 427 | INFOPLIST_FILE = SwiftUINavigation/Info.plist; 428 | LD_RUNPATH_SEARCH_PATHS = ( 429 | "$(inherited)", 430 | "@executable_path/Frameworks", 431 | ); 432 | PRODUCT_BUNDLE_IDENTIFIER = com.azharkova.SwiftUINavigation; 433 | PRODUCT_NAME = "$(TARGET_NAME)"; 434 | SWIFT_VERSION = 5.0; 435 | TARGETED_DEVICE_FAMILY = "1,2"; 436 | }; 437 | name = Release; 438 | }; 439 | /* End XCBuildConfiguration section */ 440 | 441 | /* Begin XCConfigurationList section */ 442 | 1DD1AC5425053A850013CA37 /* Build configuration list for PBXProject "SwiftUINavigation" */ = { 443 | isa = XCConfigurationList; 444 | buildConfigurations = ( 445 | 1DD1AC6B25053A890013CA37 /* Debug */, 446 | 1DD1AC6C25053A890013CA37 /* Release */, 447 | ); 448 | defaultConfigurationIsVisible = 0; 449 | defaultConfigurationName = Release; 450 | }; 451 | 1DD1AC6D25053A890013CA37 /* Build configuration list for PBXNativeTarget "SwiftUINavigation" */ = { 452 | isa = XCConfigurationList; 453 | buildConfigurations = ( 454 | 1DD1AC6E25053A890013CA37 /* Debug */, 455 | 1DD1AC6F25053A890013CA37 /* Release */, 456 | ); 457 | defaultConfigurationIsVisible = 0; 458 | defaultConfigurationName = Release; 459 | }; 460 | /* End XCConfigurationList section */ 461 | }; 462 | rootObject = 1DD1AC5125053A850013CA37 /* Project object */; 463 | } 464 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | 12 | struct FirstView: View, IItemView { 13 | var listener: INavigationContainer? 14 | var body: some View { 15 | VStack { 16 | Text("FirstView") 17 | Button(action: { 18 | self.listener?.push(view:SecondView()) 19 | }) { Text("To second") 20 | } 21 | }.onAppear { 22 | print("Appear first") 23 | }.onDisappear { 24 | print("Disappear first") 25 | } 26 | } 27 | } 28 | 29 | struct SecondView: View,IItemView { 30 | var listener: INavigationContainer? 31 | 32 | var body: some View { 33 | VStack { 34 | Text("SecondView") 35 | Button(action: { 36 | self.listener?.push(view: ThirdView()) 37 | }) { Text("To third") 38 | } 39 | Button(action: { 40 | self.listener?.pop() 41 | }) { Text("back") 42 | } 43 | }.onAppear { 44 | print("Appear sec") 45 | }.onDisappear { 46 | print("Disappear sec") 47 | } 48 | } 49 | } 50 | 51 | struct ThirdView: View,IItemView { 52 | var listener: INavigationContainer? 53 | 54 | var body: some View { 55 | VStack { 56 | Text("ThirdView") 57 | Button(action: { 58 | self.listener?.pop() 59 | }) { Text("To second") 60 | } 61 | Button(action: { 62 | self.listener?.popToRoot() 63 | }) { Text("To root") 64 | } 65 | }.onAppear { 66 | print("Appear third") 67 | }.onDisappear { 68 | print("Disappear third") 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/MyApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MyApp.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 17.10.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | 12 | @main 13 | struct MyApp : App { 14 | var body: some Scene { 15 | WindowGroup { 16 | NavigationContainerView(transition: .custom(.slide)) { 17 | FirstView() 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/container/ContainerModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContainerModel.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Combine 11 | 12 | 13 | class ContainerModel:ObservableObject { 14 | @Published var hasError: Bool = false 15 | @Published var errorText: String = "" 16 | @Published var isLoading: Bool = false 17 | 18 | func setupError(error: String){ 19 | self.errorText = error 20 | if (!error.isEmpty) { 21 | self.hasError = true 22 | } 23 | } 24 | 25 | func errorShown() { 26 | self.hasError = false 27 | self.errorText = "" 28 | } 29 | 30 | func showLoading() { 31 | self.isLoading = true 32 | } 33 | 34 | func hideLoading() { 35 | self.isLoading = false 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/container/ContainerView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContainerView.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | import Combine 12 | 13 | struct ContainerView: IContainer, View where Content: View&IModelView { 14 | @ObservedObject var containerModel = ContainerModel() 15 | private var content: Content 16 | 17 | public init(content: Content) { 18 | self.content = content 19 | self.content.viewModel?.listener = self 20 | } 21 | 22 | var body : some View { 23 | ZStack { 24 | content 25 | if (self.containerModel.isLoading) { 26 | LoaderView() 27 | } 28 | }.alert(isPresented: $containerModel.hasError){ 29 | Alert(title: Text(""), message: Text(containerModel.errorText), dismissButton: .default(Text("OK")){ 30 | self.containerModel.errorShown() 31 | }) 32 | } 33 | } 34 | 35 | func showError(error: String) { 36 | self.containerModel.setupError(error: error) 37 | } 38 | 39 | func showLoading() { 40 | self.containerModel.showLoading() 41 | } 42 | 43 | func hideLoading() { 44 | self.containerModel.hideLoading() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/container/IModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IModel.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Foundation 11 | protocol IModel:class { 12 | func update(data: Any?) 13 | var listener:IContainer? {get set} 14 | 15 | } 16 | 17 | protocol IContainer { 18 | func showError(error: String) 19 | 20 | func showLoading() 21 | 22 | func hideLoading() 23 | } 24 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/container/IModelView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IModelView.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Foundation 11 | 12 | protocol IModelView { 13 | var viewModel: IModel? {get} 14 | 15 | func showError(error: String) 16 | 17 | func showLoading() 18 | 19 | func hideLoading() 20 | } 21 | 22 | 23 | extension IModelView { 24 | func showError(error: String) { 25 | self.viewModel?.listener?.showError(error: error) 26 | } 27 | 28 | func showLoading() { 29 | self.viewModel?.listener?.showLoading() 30 | } 31 | 32 | func hideLoading() { 33 | self.viewModel?.listener?.hideLoading() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/container/LazyView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LazyView.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Foundation 11 | import SwiftUI 12 | 13 | struct LazyView: View { 14 | let build: () -> Content 15 | init(_ build: @autoclosure @escaping () -> Content) { 16 | self.build = build 17 | } 18 | var body: Content { 19 | build() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/container/LoaderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LoaderView.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct LoaderView: View { 12 | var body: some View { 13 | ZStack { 14 | Color(red: 0.0, green: 0.0, blue: 0.0, opacity: 0.45) 15 | .edgesIgnoringSafeArea(.all) 16 | 17 | VStack { 18 | Text("Loading...") 19 | .multilineTextAlignment(.center) 20 | // ActivityIndicator(isAnimating: .constant(true), style: .large) 21 | } 22 | .padding(20) 23 | .overlay( 24 | RoundedRectangle(cornerRadius: 5) 25 | .stroke(Color.white, lineWidth: 2) 26 | ) 27 | .background(Color.white) 28 | } 29 | } 30 | } 31 | 32 | struct LoaderView_Previews: PreviewProvider { 33 | static var previews: some View { 34 | LoaderView() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/extension/View+Any.swift: -------------------------------------------------------------------------------- 1 | // 2 | // View+Any.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | extension View { 12 | 13 | func toAnyView() -> AnyView { 14 | AnyView(self) 15 | } 16 | } 17 | 18 | extension EnvironmentObject { 19 | var hasValue: Bool { 20 | !String(describing: self).contains("_store: nil") 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/extension/View+Navigation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // View+Navigation.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 07.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | 12 | protocol INavigationItemView { 13 | func push(view: AnyView) 14 | 15 | func pop() 16 | 17 | func popToRoot() 18 | } 19 | 20 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigation/NavigationItemContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NavigationItemContainer.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 07.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | protocol IItemView:View { 12 | var listener: INavigationContainer? {get set} 13 | } 14 | 15 | 16 | protocol INavigationContainer { 17 | 18 | func push(view: Content) 19 | 20 | func pop() 21 | 22 | func popToRoot() 23 | } 24 | 25 | 26 | struct NavigationItemContainer: View , INavigationContainer where Content:View&IItemView{ 27 | var viewModel = NavigationViewModel.shared 28 | //@EnvironmentObject var vm: NavigationViewModel 29 | 30 | @State var title: String = "" 31 | 32 | private var contentView: Content 33 | 34 | public init(content: Content, _ title: String = "") { 35 | self.contentView = content 36 | self.contentView.listener = self 37 | } 38 | 39 | var body: some View { 40 | return ZStack { 41 | self.contentView 42 | }.background(Color.white) 43 | } 44 | 45 | 46 | func push(view: Content) { 47 | let item = NavigationItemContainer(content: view) 48 | self.viewModel.push(item.toAnyView()) 49 | } 50 | 51 | func pop() { 52 | self.viewModel.pop() 53 | } 54 | 55 | func popToRoot() { 56 | self.viewModel.popToRoot() 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigation/NavigationStack.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NavigationStack.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct NavigationStack { 12 | 13 | private var screens = [Screen]() 14 | 15 | func top() -> Screen? { 16 | self.screens.last 17 | } 18 | 19 | mutating func push(_ s: Screen) { 20 | self.screens.append(s) 21 | } 22 | 23 | mutating func popToPrevious() { 24 | _ = self.screens.popLast() 25 | } 26 | 27 | mutating func popToRoot() { 28 | self.screens.removeAll() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigation/NavigationViewContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NavigationViewContainer.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | 12 | enum Transition { 13 | case none 14 | case custom(AnyTransition) 15 | } 16 | 17 | enum NavigationType { 18 | case push 19 | case pop 20 | case popToRoot 21 | } 22 | 23 | 24 | struct NavigationContainerView: View where Content: View&IItemView{ 25 | @ObservedObject private var viewModel: NavigationViewModel = NavigationViewModel.shared 26 | private let animation: Animation = .easeOut(duration: 0.33) 27 | private let content: NavigationItemContainer 28 | private let transition: (push: AnyTransition, pop: AnyTransition) 29 | 30 | init(transition: Transition, @ViewBuilder content: @escaping () -> Content) { 31 | self.content = NavigationItemContainer(content: content()) 32 | switch transition { 33 | case .custom(let transition): 34 | self.transition = (transition, transition) 35 | case .none: 36 | self.transition = (.identity, .identity) 37 | } 38 | } 39 | 40 | var body: some View { 41 | let isRoot = viewModel.currentScreen == nil 42 | return ZStack { 43 | if isRoot { 44 | content 45 | // .environmentObject(self.viewModel) 46 | .animation(self.animation) 47 | .transition(viewModel.navigationType == .push ? transition.push : transition.pop) 48 | } else { 49 | viewModel.currentScreen?.screenView 50 | //.environmentObject(viewModel) 51 | .animation(self.animation) 52 | .transition(viewModel.navigationType == .push ? transition.push : transition.pop) 53 | 54 | } 55 | } 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigation/NavigationViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NavigationModel.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | 12 | class NavigationViewModel: ObservableObject { 13 | static var shared = NavigationViewModel() 14 | 15 | 16 | @Published var currentScreen: Screen? 17 | var navigationType: NavigationType = .push 18 | 19 | private var screenStack = NavigationStack() { 20 | didSet { 21 | currentScreen = screenStack.top() 22 | } 23 | } 24 | 25 | 26 | 27 | func push(_ screenView: AnyView) { 28 | self.navigationType = .push 29 | let screen = Screen(screenView: screenView) 30 | screenStack.push(screen) 31 | 32 | } 33 | 34 | func pop() { 35 | self.navigationType = .pop 36 | screenStack.popToPrevious() 37 | } 38 | 39 | func popToRoot() { 40 | self.navigationType = .popToRoot 41 | screenStack.popToRoot() 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigation/Screen.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Screen.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | 12 | struct Screen: Identifiable, Equatable { 13 | 14 | let id: String = UUID.init().uuidString 15 | let screenView: AnyView 16 | 17 | static func == (lhs: Screen, rhs: Screen) -> Bool { 18 | lhs.id == rhs.id 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigator/IScreenView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IScreenView.swift 3 | // NewsSwiftUI 4 | // 5 | // Created by 1 on 16.02.2020. 6 | // Copyright © 2020 azharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | import UIKit 12 | 13 | protocol IScreenView{ 14 | mutating func setupParent(parent: UIViewController?) 15 | } 16 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigator/Navigator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Navigator.swift 3 | // NewsSwiftUI 4 | // 5 | // Created by 1 on 16.02.2020. 6 | // Copyright © 2020 azharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | import UIKit 12 | 13 | class Navigator { 14 | private init(){} 15 | 16 | static let shared = Navigator() 17 | 18 | private weak var view: UIViewController? 19 | 20 | internal weak var nc: UINavigationController? { 21 | get { 22 | 23 | if let scene = UIApplication.shared.connectedScenes.first, 24 | let sceneDelegate = scene as? UIWindowScene , 25 | let rootVC = sceneDelegate.windows.first?.rootViewController { 26 | if rootVC is UINavigationController { 27 | return rootVC as? UINavigationController 28 | }else { 29 | return rootVC.navigationController 30 | } 31 | } 32 | return self.view?.navigationController 33 | } 34 | } 35 | 36 | func setup(view: UIViewController) { 37 | self.view = view 38 | } 39 | 40 | 41 | internal func open(screen: Content.Type, _ data: Any? = nil) { 42 | if let vc = ModuleConfig.shared.config(screen: screen)? 43 | .createScreen(data) { 44 | self.nc?.pushViewController(vc, animated: true) 45 | } 46 | } 47 | 48 | internal func present(screen: Content.Type, _ data: Any? = nil) { 49 | if let vc = ModuleConfig.shared.config(screen: screen)? 50 | .createScreen(data) { 51 | nc?.present(UINavigationController(rootViewController: vc), animated: true, completion: nil) 52 | } 53 | } 54 | 55 | internal func get(screen: Content.Type, _ data: Any? = nil)->UIViewController? { 56 | return ModuleConfig.shared.config(screen: screen)?.createScreen(data) 57 | } 58 | 59 | 60 | func setRootController(controller: UIViewController) { 61 | SceneDelegate.setupRoot(vc: controller) 62 | } 63 | 64 | func setRootController(screen: Content.Type) { 65 | if let vc = ModuleConfig.shared.config(screen: screen)? 66 | .createScreen(nil) { 67 | let nc = UINavigationController(rootViewController: vc) 68 | nc.isNavigationBarHidden = true 69 | setRootController(controller: nc) 70 | } 71 | } 72 | 73 | func back() { 74 | if (nc?.viewControllers.count == 1) { 75 | nc?.dismiss(animated: true, completion: nil) 76 | } else { 77 | nc?.popViewController(animated: true) 78 | } 79 | } 80 | 81 | 82 | func finish() { 83 | nc?.dismiss(animated: true, completion: nil) 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/navigator/config/ModuleConfig.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ModuleConfig.swift 3 | // NewsSwiftUI 4 | // 5 | // Created by 1 on 16.02.2020. 6 | // Copyright © 2020 azharkova. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | import SwiftUI 12 | 13 | protocol IConfugator: class { 14 | func createScreen(_ data: Any?)->UIViewController 15 | } 16 | 17 | class ModuleConfig{ 18 | private init(){} 19 | static let shared = ModuleConfig() 20 | 21 | func config(screen: Content.Type)->IConfugator? { 22 | /*if screen == NewsListView.self { 23 | return NewsListConfigurator.shared 24 | } 25 | if screen == NewsItemView.self { 26 | return NewsItemConfigurator.shared 27 | } 28 | if screen == SearchView.self { 29 | return SearchConfigurator.shared 30 | }*/ 31 | return nil 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/old/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | /* 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /SwiftUINavigation/SwiftUINavigation/old/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // SwiftUINavigation 4 | // 5 | // Created by Anna Zharkova on 06.09.2020. 6 | // Copyright © 2020 Anna Zharkova. All rights reserved. 7 | // 8 | /* 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 19 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 20 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 21 | 22 | // Create the SwiftUI view that provides the window contents. 23 | let contentView = ContentView() 24 | 25 | // Use a UIHostingController as window root view controller. 26 | if let windowScene = scene as? UIWindowScene { 27 | let window = UIWindow(windowScene: windowScene) 28 | window.rootViewController = UIHostingController(rootView: contentView) 29 | self.window = window 30 | window.makeKeyAndVisible() 31 | } 32 | } 33 | 34 | func sceneDidDisconnect(_ scene: UIScene) { 35 | // Called as the scene is being released by the system. 36 | // This occurs shortly after the scene enters the background, or when its session is discarded. 37 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 38 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 39 | } 40 | 41 | func sceneDidBecomeActive(_ scene: UIScene) { 42 | // Called when the scene has moved from an inactive state to an active state. 43 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 44 | } 45 | 46 | func sceneWillResignActive(_ scene: UIScene) { 47 | // Called when the scene will move from an active state to an inactive state. 48 | // This may occur due to temporary interruptions (ex. an incoming phone call). 49 | } 50 | 51 | func sceneWillEnterForeground(_ scene: UIScene) { 52 | // Called as the scene transitions from the background to the foreground. 53 | // Use this method to undo the changes made on entering the background. 54 | } 55 | 56 | func sceneDidEnterBackground(_ scene: UIScene) { 57 | // Called as the scene transitions from the foreground to the background. 58 | // Use this method to save data, release shared resources, and store enough scene-specific state information 59 | // to restore the scene back to its current state. 60 | } 61 | 62 | 63 | } 64 | 65 | */ 66 | --------------------------------------------------------------------------------