├── .gitignore ├── LICENSE ├── README.md ├── SwiftUI-ScrollView-Demo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── SwiftUI-ScrollView-Demo ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── BubbleView.swift ├── ConversationView.swift ├── Info.plist ├── Models └── Conversation.swift ├── Preview Content └── Preview Assets.xcassets │ └── Contents.json ├── ReverseScrollView.swift └── SceneDelegate.swift /.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 Mickaël Rémond 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 | # SwiftUI-ScrollView-Demo 2 | Custom Reversed Scroll View Example in pure Swift UI (used for chat conversation view) 3 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 024448462338D8A00093941F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024448452338D8A00093941F /* AppDelegate.swift */; }; 11 | 024448482338D8A00093941F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024448472338D8A00093941F /* SceneDelegate.swift */; }; 12 | 0244484A2338D8A00093941F /* ConversationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024448492338D8A00093941F /* ConversationView.swift */; }; 13 | 0244484C2338D8A10093941F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0244484B2338D8A10093941F /* Assets.xcassets */; }; 14 | 0244484F2338D8A10093941F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0244484E2338D8A10093941F /* Preview Assets.xcassets */; }; 15 | 024448522338D8A10093941F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 024448502338D8A10093941F /* LaunchScreen.storyboard */; }; 16 | 026DB8312338ED9000286F55 /* Conversation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 026DB8302338ED9000286F55 /* Conversation.swift */; }; 17 | 026DB8352339F43900286F55 /* BubbleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 026DB8342339F43900286F55 /* BubbleView.swift */; }; 18 | 026DB837233A44AD00286F55 /* ReverseScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 026DB836233A44AD00286F55 /* ReverseScrollView.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 024448422338D8A00093941F /* SwiftUI-ScrollView-Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftUI-ScrollView-Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 024448452338D8A00093941F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | 024448472338D8A00093941F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 25 | 024448492338D8A00093941F /* ConversationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationView.swift; sourceTree = ""; }; 26 | 0244484B2338D8A10093941F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | 0244484E2338D8A10093941F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 28 | 024448512338D8A10093941F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 024448532338D8A10093941F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 026DB8302338ED9000286F55 /* Conversation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conversation.swift; sourceTree = ""; }; 31 | 026DB8342339F43900286F55 /* BubbleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BubbleView.swift; sourceTree = ""; }; 32 | 026DB836233A44AD00286F55 /* ReverseScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReverseScrollView.swift; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 0244483F2338D8A00093941F /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 024448392338D89F0093941F = { 47 | isa = PBXGroup; 48 | children = ( 49 | 024448442338D8A00093941F /* SwiftUI-ScrollView-Demo */, 50 | 024448432338D8A00093941F /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | 024448432338D8A00093941F /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 024448422338D8A00093941F /* SwiftUI-ScrollView-Demo.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | 024448442338D8A00093941F /* SwiftUI-ScrollView-Demo */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 026DB82F2338EC2A00286F55 /* Models */, 66 | 024448452338D8A00093941F /* AppDelegate.swift */, 67 | 024448472338D8A00093941F /* SceneDelegate.swift */, 68 | 024448492338D8A00093941F /* ConversationView.swift */, 69 | 026DB836233A44AD00286F55 /* ReverseScrollView.swift */, 70 | 026DB8342339F43900286F55 /* BubbleView.swift */, 71 | 0244484B2338D8A10093941F /* Assets.xcassets */, 72 | 024448502338D8A10093941F /* LaunchScreen.storyboard */, 73 | 024448532338D8A10093941F /* Info.plist */, 74 | 0244484D2338D8A10093941F /* Preview Content */, 75 | ); 76 | path = "SwiftUI-ScrollView-Demo"; 77 | sourceTree = ""; 78 | }; 79 | 0244484D2338D8A10093941F /* Preview Content */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 0244484E2338D8A10093941F /* Preview Assets.xcassets */, 83 | ); 84 | path = "Preview Content"; 85 | sourceTree = ""; 86 | }; 87 | 026DB82F2338EC2A00286F55 /* Models */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 026DB8302338ED9000286F55 /* Conversation.swift */, 91 | ); 92 | path = Models; 93 | sourceTree = ""; 94 | }; 95 | /* End PBXGroup section */ 96 | 97 | /* Begin PBXNativeTarget section */ 98 | 024448412338D8A00093941F /* SwiftUI-ScrollView-Demo */ = { 99 | isa = PBXNativeTarget; 100 | buildConfigurationList = 024448562338D8A10093941F /* Build configuration list for PBXNativeTarget "SwiftUI-ScrollView-Demo" */; 101 | buildPhases = ( 102 | 0244483E2338D8A00093941F /* Sources */, 103 | 0244483F2338D8A00093941F /* Frameworks */, 104 | 024448402338D8A00093941F /* Resources */, 105 | ); 106 | buildRules = ( 107 | ); 108 | dependencies = ( 109 | ); 110 | name = "SwiftUI-ScrollView-Demo"; 111 | productName = "SwiftUI-ScrollView-Demo"; 112 | productReference = 024448422338D8A00093941F /* SwiftUI-ScrollView-Demo.app */; 113 | productType = "com.apple.product-type.application"; 114 | }; 115 | /* End PBXNativeTarget section */ 116 | 117 | /* Begin PBXProject section */ 118 | 0244483A2338D89F0093941F /* Project object */ = { 119 | isa = PBXProject; 120 | attributes = { 121 | LastSwiftUpdateCheck = 1100; 122 | LastUpgradeCheck = 1100; 123 | ORGANIZATIONNAME = ProcessOne; 124 | TargetAttributes = { 125 | 024448412338D8A00093941F = { 126 | CreatedOnToolsVersion = 11.0; 127 | }; 128 | }; 129 | }; 130 | buildConfigurationList = 0244483D2338D89F0093941F /* Build configuration list for PBXProject "SwiftUI-ScrollView-Demo" */; 131 | compatibilityVersion = "Xcode 9.3"; 132 | developmentRegion = en; 133 | hasScannedForEncodings = 0; 134 | knownRegions = ( 135 | en, 136 | Base, 137 | ); 138 | mainGroup = 024448392338D89F0093941F; 139 | productRefGroup = 024448432338D8A00093941F /* Products */; 140 | projectDirPath = ""; 141 | projectRoot = ""; 142 | targets = ( 143 | 024448412338D8A00093941F /* SwiftUI-ScrollView-Demo */, 144 | ); 145 | }; 146 | /* End PBXProject section */ 147 | 148 | /* Begin PBXResourcesBuildPhase section */ 149 | 024448402338D8A00093941F /* Resources */ = { 150 | isa = PBXResourcesBuildPhase; 151 | buildActionMask = 2147483647; 152 | files = ( 153 | 024448522338D8A10093941F /* LaunchScreen.storyboard in Resources */, 154 | 0244484F2338D8A10093941F /* Preview Assets.xcassets in Resources */, 155 | 0244484C2338D8A10093941F /* Assets.xcassets in Resources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXResourcesBuildPhase section */ 160 | 161 | /* Begin PBXSourcesBuildPhase section */ 162 | 0244483E2338D8A00093941F /* Sources */ = { 163 | isa = PBXSourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | 026DB8352339F43900286F55 /* BubbleView.swift in Sources */, 167 | 026DB8312338ED9000286F55 /* Conversation.swift in Sources */, 168 | 024448462338D8A00093941F /* AppDelegate.swift in Sources */, 169 | 024448482338D8A00093941F /* SceneDelegate.swift in Sources */, 170 | 026DB837233A44AD00286F55 /* ReverseScrollView.swift in Sources */, 171 | 0244484A2338D8A00093941F /* ConversationView.swift in Sources */, 172 | ); 173 | runOnlyForDeploymentPostprocessing = 0; 174 | }; 175 | /* End PBXSourcesBuildPhase section */ 176 | 177 | /* Begin PBXVariantGroup section */ 178 | 024448502338D8A10093941F /* LaunchScreen.storyboard */ = { 179 | isa = PBXVariantGroup; 180 | children = ( 181 | 024448512338D8A10093941F /* Base */, 182 | ); 183 | name = LaunchScreen.storyboard; 184 | sourceTree = ""; 185 | }; 186 | /* End PBXVariantGroup section */ 187 | 188 | /* Begin XCBuildConfiguration section */ 189 | 024448542338D8A10093941F /* Debug */ = { 190 | isa = XCBuildConfiguration; 191 | buildSettings = { 192 | ALWAYS_SEARCH_USER_PATHS = NO; 193 | CLANG_ANALYZER_NONNULL = YES; 194 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 195 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 196 | CLANG_CXX_LIBRARY = "libc++"; 197 | CLANG_ENABLE_MODULES = YES; 198 | CLANG_ENABLE_OBJC_ARC = YES; 199 | CLANG_ENABLE_OBJC_WEAK = YES; 200 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 201 | CLANG_WARN_BOOL_CONVERSION = YES; 202 | CLANG_WARN_COMMA = YES; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 205 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 206 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 207 | CLANG_WARN_EMPTY_BODY = YES; 208 | CLANG_WARN_ENUM_CONVERSION = YES; 209 | CLANG_WARN_INFINITE_RECURSION = YES; 210 | CLANG_WARN_INT_CONVERSION = YES; 211 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 212 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 213 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 214 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 215 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 216 | CLANG_WARN_STRICT_PROTOTYPES = YES; 217 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 218 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 219 | CLANG_WARN_UNREACHABLE_CODE = YES; 220 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 221 | COPY_PHASE_STRIP = NO; 222 | DEBUG_INFORMATION_FORMAT = dwarf; 223 | ENABLE_STRICT_OBJC_MSGSEND = YES; 224 | ENABLE_TESTABILITY = YES; 225 | GCC_C_LANGUAGE_STANDARD = gnu11; 226 | GCC_DYNAMIC_NO_PIC = NO; 227 | GCC_NO_COMMON_BLOCKS = YES; 228 | GCC_OPTIMIZATION_LEVEL = 0; 229 | GCC_PREPROCESSOR_DEFINITIONS = ( 230 | "DEBUG=1", 231 | "$(inherited)", 232 | ); 233 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 234 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 235 | GCC_WARN_UNDECLARED_SELECTOR = YES; 236 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 237 | GCC_WARN_UNUSED_FUNCTION = YES; 238 | GCC_WARN_UNUSED_VARIABLE = YES; 239 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 240 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 241 | MTL_FAST_MATH = YES; 242 | ONLY_ACTIVE_ARCH = YES; 243 | SDKROOT = iphoneos; 244 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 245 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 246 | }; 247 | name = Debug; 248 | }; 249 | 024448552338D8A10093941F /* Release */ = { 250 | isa = XCBuildConfiguration; 251 | buildSettings = { 252 | ALWAYS_SEARCH_USER_PATHS = NO; 253 | CLANG_ANALYZER_NONNULL = YES; 254 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 255 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 256 | CLANG_CXX_LIBRARY = "libc++"; 257 | CLANG_ENABLE_MODULES = YES; 258 | CLANG_ENABLE_OBJC_ARC = YES; 259 | CLANG_ENABLE_OBJC_WEAK = YES; 260 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 261 | CLANG_WARN_BOOL_CONVERSION = YES; 262 | CLANG_WARN_COMMA = YES; 263 | CLANG_WARN_CONSTANT_CONVERSION = YES; 264 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 265 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 266 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 267 | CLANG_WARN_EMPTY_BODY = YES; 268 | CLANG_WARN_ENUM_CONVERSION = YES; 269 | CLANG_WARN_INFINITE_RECURSION = YES; 270 | CLANG_WARN_INT_CONVERSION = YES; 271 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 272 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 273 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 276 | CLANG_WARN_STRICT_PROTOTYPES = YES; 277 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 278 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 279 | CLANG_WARN_UNREACHABLE_CODE = YES; 280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 281 | COPY_PHASE_STRIP = NO; 282 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 283 | ENABLE_NS_ASSERTIONS = NO; 284 | ENABLE_STRICT_OBJC_MSGSEND = YES; 285 | GCC_C_LANGUAGE_STANDARD = gnu11; 286 | GCC_NO_COMMON_BLOCKS = YES; 287 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 288 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 289 | GCC_WARN_UNDECLARED_SELECTOR = YES; 290 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 291 | GCC_WARN_UNUSED_FUNCTION = YES; 292 | GCC_WARN_UNUSED_VARIABLE = YES; 293 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 294 | MTL_ENABLE_DEBUG_INFO = NO; 295 | MTL_FAST_MATH = YES; 296 | SDKROOT = iphoneos; 297 | SWIFT_COMPILATION_MODE = wholemodule; 298 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 299 | VALIDATE_PRODUCT = YES; 300 | }; 301 | name = Release; 302 | }; 303 | 024448572338D8A10093941F /* Debug */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 307 | CODE_SIGN_STYLE = Automatic; 308 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUI-ScrollView-Demo/Preview Content\""; 309 | DEVELOPMENT_TEAM = 8L55BDM864; 310 | ENABLE_PREVIEWS = YES; 311 | INFOPLIST_FILE = "SwiftUI-ScrollView-Demo/Info.plist"; 312 | LD_RUNPATH_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | "@executable_path/Frameworks", 315 | ); 316 | PRODUCT_BUNDLE_IDENTIFIER = "net.process-one.SwiftUI-ScrollView-Demo"; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_VERSION = 5.0; 319 | TARGETED_DEVICE_FAMILY = "1,2"; 320 | }; 321 | name = Debug; 322 | }; 323 | 024448582338D8A10093941F /* Release */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 327 | CODE_SIGN_STYLE = Automatic; 328 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUI-ScrollView-Demo/Preview Content\""; 329 | DEVELOPMENT_TEAM = 8L55BDM864; 330 | ENABLE_PREVIEWS = YES; 331 | INFOPLIST_FILE = "SwiftUI-ScrollView-Demo/Info.plist"; 332 | LD_RUNPATH_SEARCH_PATHS = ( 333 | "$(inherited)", 334 | "@executable_path/Frameworks", 335 | ); 336 | PRODUCT_BUNDLE_IDENTIFIER = "net.process-one.SwiftUI-ScrollView-Demo"; 337 | PRODUCT_NAME = "$(TARGET_NAME)"; 338 | SWIFT_VERSION = 5.0; 339 | TARGETED_DEVICE_FAMILY = "1,2"; 340 | }; 341 | name = Release; 342 | }; 343 | /* End XCBuildConfiguration section */ 344 | 345 | /* Begin XCConfigurationList section */ 346 | 0244483D2338D89F0093941F /* Build configuration list for PBXProject "SwiftUI-ScrollView-Demo" */ = { 347 | isa = XCConfigurationList; 348 | buildConfigurations = ( 349 | 024448542338D8A10093941F /* Debug */, 350 | 024448552338D8A10093941F /* Release */, 351 | ); 352 | defaultConfigurationIsVisible = 0; 353 | defaultConfigurationName = Release; 354 | }; 355 | 024448562338D8A10093941F /* Build configuration list for PBXNativeTarget "SwiftUI-ScrollView-Demo" */ = { 356 | isa = XCConfigurationList; 357 | buildConfigurations = ( 358 | 024448572338D8A10093941F /* Debug */, 359 | 024448582338D8A10093941F /* Release */, 360 | ); 361 | defaultConfigurationIsVisible = 0; 362 | defaultConfigurationName = Release; 363 | }; 364 | /* End XCConfigurationList section */ 365 | }; 366 | rootObject = 0244483A2338D89F0093941F /* Project object */; 367 | } 368 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftUI-ScrollView-Demo 4 | // 5 | // Created by Mickaël Rémond on 23/09/2019. 6 | // Copyright © 2019 ProcessOne. 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 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/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 | } -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/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 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/BubbleView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BubbleView.swift 3 | // SwiftUI-ScrollView-Demo 4 | // 5 | 6 | import SwiftUI 7 | 8 | struct BubbleView: View { 9 | var message: String 10 | 11 | var body: some View { 12 | HStack { 13 | Spacer() 14 | Text(message) 15 | } 16 | .padding(10) 17 | .background(Color.gray) 18 | } 19 | } 20 | 21 | struct BubbleView_Previews: PreviewProvider { 22 | static var previews: some View { 23 | BubbleView(message: "Hello") 24 | .previewLayout(.sizeThatFits) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/ConversationView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConversationView.swift 3 | // SwiftUI-ScrollView-Demo 4 | // 5 | 6 | import SwiftUI 7 | 8 | struct ConversationView: View { 9 | var conversation: Conversation 10 | 11 | var body: some View { 12 | NavigationView { 13 | ReverseScrollView { 14 | VStack(spacing: 8) { 15 | ForEach(self.conversation.messages) { message in 16 | return BubbleView(message: message.body) 17 | } 18 | } 19 | } 20 | .navigationBarTitle(Text("Conversation")) 21 | } 22 | } 23 | } 24 | 25 | struct ContentView_Previews: PreviewProvider { 26 | static var previews: some View { 27 | ConversationView(conversation: demoConversation) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/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 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/Models/Conversation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Conversation.swift 3 | // SwiftUI-ScrollView-Demo 4 | // 5 | 6 | struct Conversation: Hashable, Codable { 7 | var messages: [Message] = [] 8 | } 9 | 10 | struct Message: Hashable, Codable, Identifiable { 11 | public var id: Int 12 | let body: String 13 | // TODO: add more fields (from, to, timestamp, read indicators, etc). 14 | } 15 | 16 | // Create demo conversation to test our custom scroll view. 17 | let demoConversation: Conversation = { 18 | var conversation = Conversation() 19 | for index in 0..<40 { 20 | var message = Message(id: index, body: "message \(index)") 21 | conversation.messages.append(message) 22 | } 23 | return conversation 24 | }() 25 | 26 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/ReverseScrollView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReverseScrollView.swift 3 | // SwiftUI-ScrollView-Demo 4 | // 5 | // Created by Mickaël Rémond on 24/09/2019. 6 | // Copyright © 2019 ProcessOne. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct ReverseScrollView: View where Content: View { 12 | @State private var contentHeight: CGFloat = CGFloat.zero 13 | @State private var scrollOffset: CGFloat = CGFloat.zero 14 | @State private var currentOffset: CGFloat = CGFloat.zero 15 | 16 | var content: () -> Content 17 | 18 | // Calculate content offset 19 | func offset(outerheight: CGFloat, innerheight: CGFloat) -> CGFloat { 20 | print("outerheight: \(outerheight) innerheight: \(innerheight)") 21 | 22 | let totalOffset = currentOffset + scrollOffset 23 | return -((innerheight/2 - outerheight/2) - totalOffset) 24 | } 25 | 26 | var body: some View { 27 | GeometryReader { outerGeometry in 28 | // Render the content 29 | // ... and set its sizing inside the parent 30 | self.content() 31 | .modifier(ViewHeightKey()) 32 | .onPreferenceChange(ViewHeightKey.self) { self.contentHeight = $0 } 33 | .frame(height: outerGeometry.size.height) 34 | .offset(y: self.offset(outerheight: outerGeometry.size.height, innerheight: self.contentHeight)) 35 | .clipped() 36 | .animation(.easeInOut) 37 | .gesture( 38 | DragGesture() 39 | .onChanged({ self.onDragChanged($0) }) 40 | .onEnded({ self.onDragEnded($0, outerHeight: outerGeometry.size.height)})) 41 | } 42 | } 43 | 44 | func onDragChanged(_ value: DragGesture.Value) { 45 | // Update rendered offset 46 | print("Start: \(value.startLocation.y)") 47 | print("Start: \(value.location.y)") 48 | self.scrollOffset = (value.location.y - value.startLocation.y) 49 | print("Scrolloffset: \(self.scrollOffset)") 50 | } 51 | 52 | func onDragEnded(_ value: DragGesture.Value, outerHeight: CGFloat) { 53 | // Update view to target position based on drag position 54 | let scrollOffset = value.location.y - value.startLocation.y 55 | print("Ended currentOffset=\(self.currentOffset) scrollOffset=\(scrollOffset)") 56 | 57 | let topLimit = self.contentHeight - outerHeight 58 | print("toplimit: \(topLimit)") 59 | 60 | // Negative topLimit => Content is smaller than screen size. We reset the scroll position on drag end: 61 | if topLimit < 0 { 62 | self.currentOffset = 0 63 | } else { 64 | // We cannot pass bottom limit (negative scroll) 65 | if self.currentOffset + scrollOffset < 0 { 66 | self.currentOffset = 0 67 | } else if self.currentOffset + scrollOffset > topLimit { 68 | self.currentOffset = topLimit 69 | } else { 70 | self.currentOffset += scrollOffset 71 | } 72 | } 73 | print("new currentOffset=\(self.currentOffset)") 74 | self.scrollOffset = 0 75 | } 76 | } 77 | 78 | struct ViewHeightKey: PreferenceKey { 79 | static var defaultValue: CGFloat { 0 } 80 | static func reduce(value: inout Value, nextValue: () -> Value) { 81 | value = value + nextValue() 82 | } 83 | } 84 | 85 | extension ViewHeightKey: ViewModifier { 86 | func body(content: Content) -> some View { 87 | return content.background(GeometryReader { proxy in 88 | Color.clear.preference(key: Self.self, value: proxy.size.height) 89 | }) 90 | } 91 | } 92 | 93 | struct ReverseScrollView_Previews: PreviewProvider { 94 | static var previews: some View { 95 | ReverseScrollView { 96 | VStack { 97 | ForEach(demoConversation.messages) { message in 98 | BubbleView(message: message.body) 99 | } 100 | } 101 | } 102 | .previewLayout(.sizeThatFits) 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /SwiftUI-ScrollView-Demo/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // SwiftUI-ScrollView-Demo 4 | // 5 | // Created by Mickaël Rémond on 23/09/2019. 6 | // Copyright © 2019 ProcessOne. 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 = ConversationView(conversation: demoConversation) 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 | --------------------------------------------------------------------------------