├── .gitignore ├── LICENSE ├── README.md ├── SwiftUIPagingScrollView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── SwiftUIPagingScrollView ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── ContentView.swift ├── Info.plist ├── PagingScrollView.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── SceneDelegate.swift ├── example.gif └── exampleRotation.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Pavel Zak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftUIPagingScrollView 2 | implementation of generic paging scrollView in SwiftUI since there is not such option with SwiftUI ScrollView implementation 3 | 4 | ![Example](https://github.com/izakpavel/SwiftUIPagingScrollView/blob/master/exampleRotation.gif) 5 | 6 | **Recent changes:** 7 | * cleaner interface, more fluent UI 8 | 9 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1B70ABCE2315ABA3003D8FD6 /* PagingScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B70ABCD2315ABA3003D8FD6 /* PagingScrollView.swift */; }; 11 | 1BD7F0BB2315AAFF007EA2B8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BD7F0BA2315AAFF007EA2B8 /* AppDelegate.swift */; }; 12 | 1BD7F0BD2315AAFF007EA2B8 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BD7F0BC2315AAFF007EA2B8 /* SceneDelegate.swift */; }; 13 | 1BD7F0BF2315AAFF007EA2B8 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BD7F0BE2315AAFF007EA2B8 /* ContentView.swift */; }; 14 | 1BD7F0C12315AB03007EA2B8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1BD7F0C02315AB03007EA2B8 /* Assets.xcassets */; }; 15 | 1BD7F0C42315AB03007EA2B8 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1BD7F0C32315AB03007EA2B8 /* Preview Assets.xcassets */; }; 16 | 1BD7F0C72315AB03007EA2B8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1BD7F0C52315AB03007EA2B8 /* LaunchScreen.storyboard */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 1B70ABCD2315ABA3003D8FD6 /* PagingScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingScrollView.swift; sourceTree = ""; }; 21 | 1BD7F0B72315AAFF007EA2B8 /* SwiftUIPagingScrollView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUIPagingScrollView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 1BD7F0BA2315AAFF007EA2B8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 1BD7F0BC2315AAFF007EA2B8 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 24 | 1BD7F0BE2315AAFF007EA2B8 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 25 | 1BD7F0C02315AB03007EA2B8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 1BD7F0C32315AB03007EA2B8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 27 | 1BD7F0C62315AB03007EA2B8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28 | 1BD7F0C82315AB03007EA2B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 1BD7F0B42315AAFF007EA2B8 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 1BD7F0AE2315AAFE007EA2B8 = { 43 | isa = PBXGroup; 44 | children = ( 45 | 1BD7F0B92315AAFF007EA2B8 /* SwiftUIPagingScrollView */, 46 | 1BD7F0B82315AAFF007EA2B8 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 1BD7F0B82315AAFF007EA2B8 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 1BD7F0B72315AAFF007EA2B8 /* SwiftUIPagingScrollView.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 1BD7F0B92315AAFF007EA2B8 /* SwiftUIPagingScrollView */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 1BD7F0BA2315AAFF007EA2B8 /* AppDelegate.swift */, 62 | 1BD7F0BC2315AAFF007EA2B8 /* SceneDelegate.swift */, 63 | 1BD7F0BE2315AAFF007EA2B8 /* ContentView.swift */, 64 | 1BD7F0C02315AB03007EA2B8 /* Assets.xcassets */, 65 | 1BD7F0C52315AB03007EA2B8 /* LaunchScreen.storyboard */, 66 | 1BD7F0C82315AB03007EA2B8 /* Info.plist */, 67 | 1BD7F0C22315AB03007EA2B8 /* Preview Content */, 68 | 1B70ABCD2315ABA3003D8FD6 /* PagingScrollView.swift */, 69 | ); 70 | path = SwiftUIPagingScrollView; 71 | sourceTree = ""; 72 | }; 73 | 1BD7F0C22315AB03007EA2B8 /* Preview Content */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 1BD7F0C32315AB03007EA2B8 /* Preview Assets.xcassets */, 77 | ); 78 | path = "Preview Content"; 79 | sourceTree = ""; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | 1BD7F0B62315AAFF007EA2B8 /* SwiftUIPagingScrollView */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = 1BD7F0CB2315AB03007EA2B8 /* Build configuration list for PBXNativeTarget "SwiftUIPagingScrollView" */; 87 | buildPhases = ( 88 | 1BD7F0B32315AAFF007EA2B8 /* Sources */, 89 | 1BD7F0B42315AAFF007EA2B8 /* Frameworks */, 90 | 1BD7F0B52315AAFF007EA2B8 /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = SwiftUIPagingScrollView; 97 | productName = SwiftUIPagingScrollView; 98 | productReference = 1BD7F0B72315AAFF007EA2B8 /* SwiftUIPagingScrollView.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | 1BD7F0AF2315AAFE007EA2B8 /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastSwiftUpdateCheck = 1100; 108 | LastUpgradeCheck = 1100; 109 | ORGANIZATIONNAME = Nerdyak; 110 | TargetAttributes = { 111 | 1BD7F0B62315AAFF007EA2B8 = { 112 | CreatedOnToolsVersion = 11.0; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = 1BD7F0B22315AAFE007EA2B8 /* Build configuration list for PBXProject "SwiftUIPagingScrollView" */; 117 | compatibilityVersion = "Xcode 9.3"; 118 | developmentRegion = en; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | Base, 123 | ); 124 | mainGroup = 1BD7F0AE2315AAFE007EA2B8; 125 | productRefGroup = 1BD7F0B82315AAFF007EA2B8 /* Products */; 126 | projectDirPath = ""; 127 | projectRoot = ""; 128 | targets = ( 129 | 1BD7F0B62315AAFF007EA2B8 /* SwiftUIPagingScrollView */, 130 | ); 131 | }; 132 | /* End PBXProject section */ 133 | 134 | /* Begin PBXResourcesBuildPhase section */ 135 | 1BD7F0B52315AAFF007EA2B8 /* Resources */ = { 136 | isa = PBXResourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 1BD7F0C72315AB03007EA2B8 /* LaunchScreen.storyboard in Resources */, 140 | 1BD7F0C42315AB03007EA2B8 /* Preview Assets.xcassets in Resources */, 141 | 1BD7F0C12315AB03007EA2B8 /* Assets.xcassets in Resources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXResourcesBuildPhase section */ 146 | 147 | /* Begin PBXSourcesBuildPhase section */ 148 | 1BD7F0B32315AAFF007EA2B8 /* Sources */ = { 149 | isa = PBXSourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 1BD7F0BB2315AAFF007EA2B8 /* AppDelegate.swift in Sources */, 153 | 1B70ABCE2315ABA3003D8FD6 /* PagingScrollView.swift in Sources */, 154 | 1BD7F0BD2315AAFF007EA2B8 /* SceneDelegate.swift in Sources */, 155 | 1BD7F0BF2315AAFF007EA2B8 /* ContentView.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | 1BD7F0C52315AB03007EA2B8 /* LaunchScreen.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 1BD7F0C62315AB03007EA2B8 /* Base */, 166 | ); 167 | name = LaunchScreen.storyboard; 168 | sourceTree = ""; 169 | }; 170 | /* End PBXVariantGroup section */ 171 | 172 | /* Begin XCBuildConfiguration section */ 173 | 1BD7F0C92315AB03007EA2B8 /* Debug */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | CLANG_ANALYZER_NONNULL = YES; 178 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 179 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 180 | CLANG_CXX_LIBRARY = "libc++"; 181 | CLANG_ENABLE_MODULES = YES; 182 | CLANG_ENABLE_OBJC_ARC = YES; 183 | CLANG_ENABLE_OBJC_WEAK = YES; 184 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_COMMA = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 190 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 191 | CLANG_WARN_EMPTY_BODY = YES; 192 | CLANG_WARN_ENUM_CONVERSION = YES; 193 | CLANG_WARN_INFINITE_RECURSION = YES; 194 | CLANG_WARN_INT_CONVERSION = YES; 195 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 197 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 198 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 199 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 200 | CLANG_WARN_STRICT_PROTOTYPES = YES; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | COPY_PHASE_STRIP = NO; 206 | DEBUG_INFORMATION_FORMAT = dwarf; 207 | ENABLE_STRICT_OBJC_MSGSEND = YES; 208 | ENABLE_TESTABILITY = YES; 209 | GCC_C_LANGUAGE_STANDARD = gnu11; 210 | GCC_DYNAMIC_NO_PIC = NO; 211 | GCC_NO_COMMON_BLOCKS = YES; 212 | GCC_OPTIMIZATION_LEVEL = 0; 213 | GCC_PREPROCESSOR_DEFINITIONS = ( 214 | "DEBUG=1", 215 | "$(inherited)", 216 | ); 217 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNUSED_FUNCTION = YES; 222 | GCC_WARN_UNUSED_VARIABLE = YES; 223 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 224 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 225 | MTL_FAST_MATH = YES; 226 | ONLY_ACTIVE_ARCH = YES; 227 | SDKROOT = iphoneos; 228 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 229 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 230 | }; 231 | name = Debug; 232 | }; 233 | 1BD7F0CA2315AB03007EA2B8 /* Release */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_ANALYZER_NONNULL = YES; 238 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_ENABLE_OBJC_WEAK = YES; 244 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 245 | CLANG_WARN_BOOL_CONVERSION = YES; 246 | CLANG_WARN_COMMA = YES; 247 | CLANG_WARN_CONSTANT_CONVERSION = YES; 248 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 251 | CLANG_WARN_EMPTY_BODY = YES; 252 | CLANG_WARN_ENUM_CONVERSION = YES; 253 | CLANG_WARN_INFINITE_RECURSION = YES; 254 | CLANG_WARN_INT_CONVERSION = YES; 255 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 256 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 257 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 258 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 259 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 260 | CLANG_WARN_STRICT_PROTOTYPES = YES; 261 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 262 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 263 | CLANG_WARN_UNREACHABLE_CODE = YES; 264 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 265 | COPY_PHASE_STRIP = NO; 266 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 267 | ENABLE_NS_ASSERTIONS = NO; 268 | ENABLE_STRICT_OBJC_MSGSEND = YES; 269 | GCC_C_LANGUAGE_STANDARD = gnu11; 270 | GCC_NO_COMMON_BLOCKS = YES; 271 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 272 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 273 | GCC_WARN_UNDECLARED_SELECTOR = YES; 274 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 275 | GCC_WARN_UNUSED_FUNCTION = YES; 276 | GCC_WARN_UNUSED_VARIABLE = YES; 277 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 278 | MTL_ENABLE_DEBUG_INFO = NO; 279 | MTL_FAST_MATH = YES; 280 | SDKROOT = iphoneos; 281 | SWIFT_COMPILATION_MODE = wholemodule; 282 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 283 | VALIDATE_PRODUCT = YES; 284 | }; 285 | name = Release; 286 | }; 287 | 1BD7F0CC2315AB03007EA2B8 /* Debug */ = { 288 | isa = XCBuildConfiguration; 289 | buildSettings = { 290 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 291 | CODE_SIGN_STYLE = Automatic; 292 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUIPagingScrollView/Preview Content\""; 293 | DEVELOPMENT_TEAM = 429H9B36BJ; 294 | ENABLE_PREVIEWS = YES; 295 | INFOPLIST_FILE = SwiftUIPagingScrollView/Info.plist; 296 | LD_RUNPATH_SEARCH_PATHS = ( 297 | "$(inherited)", 298 | "@executable_path/Frameworks", 299 | ); 300 | PRODUCT_BUNDLE_IDENTIFIER = com.nerdyak.SwiftUIPagingScrollView; 301 | PRODUCT_NAME = "$(TARGET_NAME)"; 302 | SWIFT_VERSION = 5.0; 303 | TARGETED_DEVICE_FAMILY = "1,2"; 304 | }; 305 | name = Debug; 306 | }; 307 | 1BD7F0CD2315AB03007EA2B8 /* Release */ = { 308 | isa = XCBuildConfiguration; 309 | buildSettings = { 310 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 311 | CODE_SIGN_STYLE = Automatic; 312 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUIPagingScrollView/Preview Content\""; 313 | DEVELOPMENT_TEAM = 429H9B36BJ; 314 | ENABLE_PREVIEWS = YES; 315 | INFOPLIST_FILE = SwiftUIPagingScrollView/Info.plist; 316 | LD_RUNPATH_SEARCH_PATHS = ( 317 | "$(inherited)", 318 | "@executable_path/Frameworks", 319 | ); 320 | PRODUCT_BUNDLE_IDENTIFIER = com.nerdyak.SwiftUIPagingScrollView; 321 | PRODUCT_NAME = "$(TARGET_NAME)"; 322 | SWIFT_VERSION = 5.0; 323 | TARGETED_DEVICE_FAMILY = "1,2"; 324 | }; 325 | name = Release; 326 | }; 327 | /* End XCBuildConfiguration section */ 328 | 329 | /* Begin XCConfigurationList section */ 330 | 1BD7F0B22315AAFE007EA2B8 /* Build configuration list for PBXProject "SwiftUIPagingScrollView" */ = { 331 | isa = XCConfigurationList; 332 | buildConfigurations = ( 333 | 1BD7F0C92315AB03007EA2B8 /* Debug */, 334 | 1BD7F0CA2315AB03007EA2B8 /* Release */, 335 | ); 336 | defaultConfigurationIsVisible = 0; 337 | defaultConfigurationName = Release; 338 | }; 339 | 1BD7F0CB2315AB03007EA2B8 /* Build configuration list for PBXNativeTarget "SwiftUIPagingScrollView" */ = { 340 | isa = XCConfigurationList; 341 | buildConfigurations = ( 342 | 1BD7F0CC2315AB03007EA2B8 /* Debug */, 343 | 1BD7F0CD2315AB03007EA2B8 /* Release */, 344 | ); 345 | defaultConfigurationIsVisible = 0; 346 | defaultConfigurationName = Release; 347 | }; 348 | /* End XCConfigurationList section */ 349 | }; 350 | rootObject = 1BD7F0AF2315AAFE007EA2B8 /* Project object */; 351 | } 352 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftUIPagingScrollView 4 | // 5 | // Created by myf on 27/08/2019. 6 | // Copyright © 2019 Pavel Zak. 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 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /SwiftUIPagingScrollView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SwiftUIPagingScrollView/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 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SwiftUIPagingScrollView 4 | // 5 | // Created by myf on 27/08/2019. 6 | // Copyright © 2019 Pavel Zak. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct TileView: View { 12 | let icon: String 13 | 14 | var body: some View { 15 | RoundedRectangle(cornerRadius: 20).fill(Color.gray) 16 | .overlay(Image(systemName: icon).imageScale(.large)) 17 | .frame(height: 128) 18 | } 19 | } 20 | 21 | struct ContentView: View { 22 | @State private var scrollEffectValue: Double = 13 23 | @State private var activePageIndex: Int = 0 24 | 25 | let tileWidth: CGFloat = 220 26 | let tilePadding: CGFloat = 20 27 | let numberOfTiles: Int = 5 28 | 29 | 30 | var body: some View { 31 | 32 | PagingScrollView(activePageIndex: self.$activePageIndex, tileWidth:self.tileWidth, tilePadding: self.tilePadding){ 33 | ForEach(0 ..< self.numberOfTiles, id: \.self) { index in 34 | GeometryReader { geometry2 in 35 | TileView(icon: "\(index + 1).circle") 36 | .rotation3DEffect(Angle(degrees: Double((geometry2.frame(in: .global).minX - self.tileWidth*0.5) / -10 )), axis: (x: 2, y: 11, z: 1)) 37 | .onTapGesture { 38 | print ("tap on index: \(index)") 39 | } 40 | } 41 | } 42 | } 43 | .frame(height: 128) 44 | 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView/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 | -------------------------------------------------------------------------------- /SwiftUIPagingScrollView/PagingScrollView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PagingScrollView.swift 3 | // SwiftUIPagingScrollView 4 | // 5 | // Created by myf on 27/08/2019. 6 | // Copyright © 2019 Pavel Zak. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct FrameMeasurePreferenceKey: PreferenceKey { 12 | typealias Value = [String: CGRect] 13 | 14 | static var defaultValue: Value = Value() 15 | 16 | static func reduce(value: inout Value, nextValue: () -> Value) { 17 | value.merge(nextValue()) { current, new in 18 | new 19 | } 20 | } 21 | } 22 | 23 | struct MeasureGeometry: View { 24 | let space: CoordinateSpace 25 | let identifier: String 26 | // this dummy view will measure the view and store its width to preference value 27 | var body: some View { 28 | GeometryReader { geometry in 29 | Color.clear 30 | .preference(key: FrameMeasurePreferenceKey.self, value: [identifier: geometry.frame(in: space)]) 31 | } 32 | } 33 | } 34 | 35 | struct PagingScrollView: View { 36 | let items: [AnyView] 37 | 38 | public init(activePageIndex:Binding, tileWidth:CGFloat, tilePadding: CGFloat, @ViewBuilder content: () -> ForEach) { 39 | let views = content() 40 | self.items = views.data.map({ AnyView(views.content($0)) }) 41 | 42 | let itemCount = views.data.count 43 | 44 | self._activePageIndex = activePageIndex 45 | 46 | self.tileWidth = tileWidth 47 | self.tilePadding = tilePadding 48 | self.itemCount = itemCount 49 | } 50 | 51 | /// index of current page 0..N-1 52 | @Binding var activePageIndex : Int 53 | 54 | /// pageWidth==frameWidth used to properly compute offsets 55 | @State var pageWidth: CGFloat = 0 56 | 57 | /// width of item / tile 58 | let tileWidth : CGFloat 59 | 60 | /// padding between items 61 | private let tilePadding : CGFloat 62 | 63 | private let itemCount : Int 64 | 65 | /// some damping factor to reduce liveness 66 | private let scrollDampingFactor: CGFloat = 0.66 67 | 68 | /// drag offset during drag gesture 69 | @State private var dragOffset : CGFloat = 0 70 | 71 | 72 | func offsetForPageIndex(_ index: Int)->CGFloat { 73 | return -self.baseTileOffset(index: index) 74 | } 75 | 76 | func indexPageForOffset(_ offset : CGFloat) -> Int { 77 | guard self.itemCount>0 else { 78 | return 0 79 | } 80 | let offset = self.logicalScrollOffset(trueOffset: offset) 81 | let floatIndex = (offset)/(tileWidth+tilePadding) 82 | var computedIndex = Int(round(floatIndex)) 83 | computedIndex = max(computedIndex, 0) 84 | return min(computedIndex, self.itemCount-1) 85 | } 86 | 87 | /// current scroll offset applied on items 88 | func currentScrollOffset(activePageIndex: Int, dragoffset: CGFloat)->CGFloat { 89 | return self.offsetForPageIndex(activePageIndex) + dragOffset 90 | } 91 | 92 | /// logical offset startin at 0 for the first item - this makes computing the page index easier 93 | func logicalScrollOffset(trueOffset: CGFloat)->CGFloat { 94 | return (trueOffset) * -1.0 95 | } 96 | 97 | private let animation = Animation.interpolatingSpring(mass: 0.1, stiffness: 20, damping: 1.5, initialVelocity: 0) 98 | 99 | func baseTileOffset(index: Int) -> CGFloat { 100 | return CGFloat(index)*(self.tileWidth + self.tilePadding) 101 | } 102 | 103 | var body: some View { 104 | 105 | ZStack(alignment: .center) { 106 | let globalOffset = self.currentScrollOffset(activePageIndex: self.activePageIndex, dragoffset: self.dragOffset) 107 | ForEach(0..