├── .gitignore ├── README.md ├── compositionalLayout.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── compositionalLayout ├── AppDelegate.swift ├── Assets.xcassets ├── AccentColor.colorset │ └── Contents.json ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── GridCompositionalLayout.swift ├── Info.plist ├── Model.swift ├── SceneDelegate.swift ├── SupplementaryViews.swift └── ViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | archive/ 7 | .build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata/ 17 | *.xccheckout 18 | profile 19 | *.moved-aside 20 | DerivedData 21 | *.hmap 22 | *.ipa 23 | 24 | # Bundler 25 | .bundle 26 | 27 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 28 | # Carthage/Checkouts 29 | 30 | Carthage/Build 31 | 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 35 | # 36 | # Note: if you ignore the Pods directory, make sure to uncomment 37 | # `pod install` in .travis.yml 38 | # 39 | # Pods/ 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repo contains sample code for: 2 | 3 | - https://arturgruchala.com/power-of-compositional-layout/ 4 | - https://arturgruchala.com/bidirectional-collection-view-with-orthogonalscrollingbehavior/ 5 | -------------------------------------------------------------------------------- /compositionalLayout.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | FAB9257428E1ABBB0084613D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB9257328E1ABBB0084613D /* AppDelegate.swift */; }; 11 | FAB9257628E1ABBB0084613D /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB9257528E1ABBB0084613D /* SceneDelegate.swift */; }; 12 | FAB9257828E1ABBB0084613D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB9257728E1ABBB0084613D /* ViewController.swift */; }; 13 | FAB9257B28E1ABBB0084613D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FAB9257928E1ABBB0084613D /* Main.storyboard */; }; 14 | FAB9257D28E1ABBE0084613D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FAB9257C28E1ABBE0084613D /* Assets.xcassets */; }; 15 | FAB9258028E1ABBE0084613D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FAB9257E28E1ABBE0084613D /* LaunchScreen.storyboard */; }; 16 | FAB9258828E1ACE80084613D /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB9258728E1ACE80084613D /* Model.swift */; }; 17 | FAB9258A28E1ADF60084613D /* GridCompositionalLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB9258928E1ADF60084613D /* GridCompositionalLayout.swift */; }; 18 | FACE035928E22FDC0043419B /* SupplementaryViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACE035828E22FDC0043419B /* SupplementaryViews.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | FAB9257028E1ABBB0084613D /* compositionalLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = compositionalLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | FAB9257328E1ABBB0084613D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | FAB9257528E1ABBB0084613D /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 25 | FAB9257728E1ABBB0084613D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 26 | FAB9257A28E1ABBB0084613D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | FAB9257C28E1ABBE0084613D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | FAB9257F28E1ABBE0084613D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | FAB9258128E1ABBE0084613D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | FAB9258728E1ACE80084613D /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; 31 | FAB9258928E1ADF60084613D /* GridCompositionalLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridCompositionalLayout.swift; sourceTree = ""; }; 32 | FACE035828E22FDC0043419B /* SupplementaryViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupplementaryViews.swift; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | FAB9256D28E1ABBB0084613D /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | FAB9256728E1ABBB0084613D = { 47 | isa = PBXGroup; 48 | children = ( 49 | FAB9257228E1ABBB0084613D /* compositionalLayout */, 50 | FAB9257128E1ABBB0084613D /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | FAB9257128E1ABBB0084613D /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | FAB9257028E1ABBB0084613D /* compositionalLayout.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | FAB9257228E1ABBB0084613D /* compositionalLayout */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | FAB9257328E1ABBB0084613D /* AppDelegate.swift */, 66 | FAB9257528E1ABBB0084613D /* SceneDelegate.swift */, 67 | FAB9257728E1ABBB0084613D /* ViewController.swift */, 68 | FAB9257928E1ABBB0084613D /* Main.storyboard */, 69 | FAB9257C28E1ABBE0084613D /* Assets.xcassets */, 70 | FAB9257E28E1ABBE0084613D /* LaunchScreen.storyboard */, 71 | FAB9258128E1ABBE0084613D /* Info.plist */, 72 | FAB9258728E1ACE80084613D /* Model.swift */, 73 | FAB9258928E1ADF60084613D /* GridCompositionalLayout.swift */, 74 | FACE035828E22FDC0043419B /* SupplementaryViews.swift */, 75 | ); 76 | path = compositionalLayout; 77 | sourceTree = ""; 78 | }; 79 | /* End PBXGroup section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | FAB9256F28E1ABBB0084613D /* compositionalLayout */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = FAB9258428E1ABBE0084613D /* Build configuration list for PBXNativeTarget "compositionalLayout" */; 85 | buildPhases = ( 86 | FAB9256C28E1ABBB0084613D /* Sources */, 87 | FAB9256D28E1ABBB0084613D /* Frameworks */, 88 | FAB9256E28E1ABBB0084613D /* Resources */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = compositionalLayout; 95 | productName = compositionalLayout; 96 | productReference = FAB9257028E1ABBB0084613D /* compositionalLayout.app */; 97 | productType = "com.apple.product-type.application"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | FAB9256828E1ABBB0084613D /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | BuildIndependentTargetsInParallel = 1; 106 | LastSwiftUpdateCheck = 1320; 107 | LastUpgradeCheck = 1320; 108 | TargetAttributes = { 109 | FAB9256F28E1ABBB0084613D = { 110 | CreatedOnToolsVersion = 13.2.1; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = FAB9256B28E1ABBB0084613D /* Build configuration list for PBXProject "compositionalLayout" */; 115 | compatibilityVersion = "Xcode 13.0"; 116 | developmentRegion = en; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = FAB9256728E1ABBB0084613D; 123 | productRefGroup = FAB9257128E1ABBB0084613D /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | FAB9256F28E1ABBB0084613D /* compositionalLayout */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXResourcesBuildPhase section */ 133 | FAB9256E28E1ABBB0084613D /* Resources */ = { 134 | isa = PBXResourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | FAB9258028E1ABBE0084613D /* LaunchScreen.storyboard in Resources */, 138 | FAB9257D28E1ABBE0084613D /* Assets.xcassets in Resources */, 139 | FAB9257B28E1ABBB0084613D /* Main.storyboard in Resources */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXResourcesBuildPhase section */ 144 | 145 | /* Begin PBXSourcesBuildPhase section */ 146 | FAB9256C28E1ABBB0084613D /* Sources */ = { 147 | isa = PBXSourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | FAB9257828E1ABBB0084613D /* ViewController.swift in Sources */, 151 | FACE035928E22FDC0043419B /* SupplementaryViews.swift in Sources */, 152 | FAB9258A28E1ADF60084613D /* GridCompositionalLayout.swift in Sources */, 153 | FAB9257428E1ABBB0084613D /* AppDelegate.swift in Sources */, 154 | FAB9257628E1ABBB0084613D /* SceneDelegate.swift in Sources */, 155 | FAB9258828E1ACE80084613D /* Model.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | FAB9257928E1ABBB0084613D /* Main.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | FAB9257A28E1ABBB0084613D /* Base */, 166 | ); 167 | name = Main.storyboard; 168 | sourceTree = ""; 169 | }; 170 | FAB9257E28E1ABBE0084613D /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | FAB9257F28E1ABBE0084613D /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | FAB9258228E1ABBE0084613D /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ALWAYS_SEARCH_USER_PATHS = NO; 185 | CLANG_ANALYZER_NONNULL = YES; 186 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 187 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 188 | CLANG_CXX_LIBRARY = "libc++"; 189 | CLANG_ENABLE_MODULES = YES; 190 | CLANG_ENABLE_OBJC_ARC = YES; 191 | CLANG_ENABLE_OBJC_WEAK = YES; 192 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 193 | CLANG_WARN_BOOL_CONVERSION = YES; 194 | CLANG_WARN_COMMA = YES; 195 | CLANG_WARN_CONSTANT_CONVERSION = YES; 196 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 197 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 198 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 199 | CLANG_WARN_EMPTY_BODY = YES; 200 | CLANG_WARN_ENUM_CONVERSION = YES; 201 | CLANG_WARN_INFINITE_RECURSION = YES; 202 | CLANG_WARN_INT_CONVERSION = YES; 203 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 204 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 205 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 206 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 207 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 208 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 209 | CLANG_WARN_STRICT_PROTOTYPES = YES; 210 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 211 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 212 | CLANG_WARN_UNREACHABLE_CODE = YES; 213 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 214 | COPY_PHASE_STRIP = NO; 215 | DEBUG_INFORMATION_FORMAT = dwarf; 216 | ENABLE_STRICT_OBJC_MSGSEND = YES; 217 | ENABLE_TESTABILITY = YES; 218 | GCC_C_LANGUAGE_STANDARD = gnu11; 219 | GCC_DYNAMIC_NO_PIC = NO; 220 | GCC_NO_COMMON_BLOCKS = YES; 221 | GCC_OPTIMIZATION_LEVEL = 0; 222 | GCC_PREPROCESSOR_DEFINITIONS = ( 223 | "DEBUG=1", 224 | "$(inherited)", 225 | ); 226 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 227 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 228 | GCC_WARN_UNDECLARED_SELECTOR = YES; 229 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 230 | GCC_WARN_UNUSED_FUNCTION = YES; 231 | GCC_WARN_UNUSED_VARIABLE = YES; 232 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 233 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 234 | MTL_FAST_MATH = YES; 235 | ONLY_ACTIVE_ARCH = YES; 236 | SDKROOT = iphoneos; 237 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 238 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 239 | }; 240 | name = Debug; 241 | }; 242 | FAB9258328E1ABBE0084613D /* Release */ = { 243 | isa = XCBuildConfiguration; 244 | buildSettings = { 245 | ALWAYS_SEARCH_USER_PATHS = NO; 246 | CLANG_ANALYZER_NONNULL = YES; 247 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 248 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 249 | CLANG_CXX_LIBRARY = "libc++"; 250 | CLANG_ENABLE_MODULES = YES; 251 | CLANG_ENABLE_OBJC_ARC = YES; 252 | CLANG_ENABLE_OBJC_WEAK = YES; 253 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 254 | CLANG_WARN_BOOL_CONVERSION = YES; 255 | CLANG_WARN_COMMA = YES; 256 | CLANG_WARN_CONSTANT_CONVERSION = YES; 257 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 258 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 259 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 260 | CLANG_WARN_EMPTY_BODY = YES; 261 | CLANG_WARN_ENUM_CONVERSION = YES; 262 | CLANG_WARN_INFINITE_RECURSION = YES; 263 | CLANG_WARN_INT_CONVERSION = YES; 264 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 265 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 266 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 267 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 268 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 269 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 270 | CLANG_WARN_STRICT_PROTOTYPES = YES; 271 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 272 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 273 | CLANG_WARN_UNREACHABLE_CODE = YES; 274 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 275 | COPY_PHASE_STRIP = NO; 276 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 277 | ENABLE_NS_ASSERTIONS = NO; 278 | ENABLE_STRICT_OBJC_MSGSEND = YES; 279 | GCC_C_LANGUAGE_STANDARD = gnu11; 280 | GCC_NO_COMMON_BLOCKS = YES; 281 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 282 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 283 | GCC_WARN_UNDECLARED_SELECTOR = YES; 284 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 285 | GCC_WARN_UNUSED_FUNCTION = YES; 286 | GCC_WARN_UNUSED_VARIABLE = YES; 287 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 288 | MTL_ENABLE_DEBUG_INFO = NO; 289 | MTL_FAST_MATH = YES; 290 | SDKROOT = iphoneos; 291 | SWIFT_COMPILATION_MODE = wholemodule; 292 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 293 | VALIDATE_PRODUCT = YES; 294 | }; 295 | name = Release; 296 | }; 297 | FAB9258528E1ABBE0084613D /* Debug */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 302 | CODE_SIGN_STYLE = Automatic; 303 | CURRENT_PROJECT_VERSION = 1; 304 | DEVELOPMENT_TEAM = A87MWTZ6CQ; 305 | GENERATE_INFOPLIST_FILE = YES; 306 | INFOPLIST_FILE = compositionalLayout/Info.plist; 307 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 308 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 309 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 310 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 311 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 312 | LD_RUNPATH_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | "@executable_path/Frameworks", 315 | ); 316 | MARKETING_VERSION = 1.0; 317 | PRODUCT_BUNDLE_IDENTIFIER = pl.arturgruchala.compositionalLayout; 318 | PRODUCT_NAME = "$(TARGET_NAME)"; 319 | SWIFT_EMIT_LOC_STRINGS = YES; 320 | SWIFT_VERSION = 5.0; 321 | TARGETED_DEVICE_FAMILY = "1,2"; 322 | }; 323 | name = Debug; 324 | }; 325 | FAB9258628E1ABBE0084613D /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 329 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 330 | CODE_SIGN_STYLE = Automatic; 331 | CURRENT_PROJECT_VERSION = 1; 332 | DEVELOPMENT_TEAM = A87MWTZ6CQ; 333 | GENERATE_INFOPLIST_FILE = YES; 334 | INFOPLIST_FILE = compositionalLayout/Info.plist; 335 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 336 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 337 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 338 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 339 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 340 | LD_RUNPATH_SEARCH_PATHS = ( 341 | "$(inherited)", 342 | "@executable_path/Frameworks", 343 | ); 344 | MARKETING_VERSION = 1.0; 345 | PRODUCT_BUNDLE_IDENTIFIER = pl.arturgruchala.compositionalLayout; 346 | PRODUCT_NAME = "$(TARGET_NAME)"; 347 | SWIFT_EMIT_LOC_STRINGS = YES; 348 | SWIFT_VERSION = 5.0; 349 | TARGETED_DEVICE_FAMILY = "1,2"; 350 | }; 351 | name = Release; 352 | }; 353 | /* End XCBuildConfiguration section */ 354 | 355 | /* Begin XCConfigurationList section */ 356 | FAB9256B28E1ABBB0084613D /* Build configuration list for PBXProject "compositionalLayout" */ = { 357 | isa = XCConfigurationList; 358 | buildConfigurations = ( 359 | FAB9258228E1ABBE0084613D /* Debug */, 360 | FAB9258328E1ABBE0084613D /* Release */, 361 | ); 362 | defaultConfigurationIsVisible = 0; 363 | defaultConfigurationName = Release; 364 | }; 365 | FAB9258428E1ABBE0084613D /* Build configuration list for PBXNativeTarget "compositionalLayout" */ = { 366 | isa = XCConfigurationList; 367 | buildConfigurations = ( 368 | FAB9258528E1ABBE0084613D /* Debug */, 369 | FAB9258628E1ABBE0084613D /* Release */, 370 | ); 371 | defaultConfigurationIsVisible = 0; 372 | defaultConfigurationName = Release; 373 | }; 374 | /* End XCConfigurationList section */ 375 | }; 376 | rootObject = FAB9256828E1ABBB0084613D /* Project object */; 377 | } 378 | -------------------------------------------------------------------------------- /compositionalLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /compositionalLayout.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /compositionalLayout/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // compositionalLayout 4 | // 5 | // Created by Artur Gruchała on 26/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /compositionalLayout/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /compositionalLayout/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 | -------------------------------------------------------------------------------- /compositionalLayout/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /compositionalLayout/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 | -------------------------------------------------------------------------------- /compositionalLayout/Base.lproj/Main.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 | -------------------------------------------------------------------------------- /compositionalLayout/GridCompositionalLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GridCompositionalLayout.swift 3 | // compositionalLayout 4 | // 5 | // Created by Artur Gruchała on 26/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | enum SupplementaryElements { 11 | static let collectionHeader = "collection-header" 12 | static let sectionHeader = "section-header" 13 | static let sectionSpacer = "sectionSpacer" 14 | } 15 | 16 | enum GridCompositionalLayout { 17 | static func generateLayout() -> UICollectionViewCompositionalLayout { 18 | 19 | let config = UICollectionViewCompositionalLayoutConfiguration() 20 | config.boundarySupplementaryItems = [makeCollectionHeader()] 21 | 22 | return UICollectionViewCompositionalLayout( 23 | sectionProvider: { section, _ in 24 | 25 | if section % 2 == 0 { 26 | return makeLetterSection() 27 | } 28 | return makeSection() 29 | }, 30 | configuration: config 31 | ) 32 | } 33 | 34 | private static func makeItem() -> NSCollectionLayoutItem { 35 | let item = NSCollectionLayoutItem( 36 | layoutSize: .init( 37 | widthDimension: .fractionalWidth(0.5), 38 | heightDimension: .fractionalWidth(0.5) 39 | ) 40 | ) 41 | item.contentInsets = .init(top: 0, leading: 2, bottom: 2, trailing: 2) 42 | 43 | return item 44 | } 45 | 46 | private static func makeBigItem() -> NSCollectionLayoutItem { 47 | let item = NSCollectionLayoutItem( 48 | layoutSize: .init( 49 | widthDimension: .fractionalWidth(1), 50 | heightDimension: .fractionalWidth(1) 51 | ) 52 | ) 53 | item.contentInsets = .init(top: 0, leading: 2, bottom: 0, trailing: 2) 54 | 55 | return item 56 | } 57 | 58 | private static func makeGroup() -> NSCollectionLayoutGroup { 59 | let group = NSCollectionLayoutGroup.horizontal( 60 | layoutSize: .init( 61 | widthDimension: .fractionalWidth(1), 62 | heightDimension: .fractionalWidth(0.5) 63 | ), 64 | subitems: [makeItem()] 65 | ) 66 | 67 | group.contentInsets = .init(top: 0, leading: 2, bottom: 4, trailing: 2) 68 | 69 | let groupWithBigElement = NSCollectionLayoutGroup.horizontal( 70 | layoutSize: .init( 71 | widthDimension: .fractionalWidth(1), 72 | heightDimension: .fractionalWidth(1) 73 | ), 74 | subitems: [makeBigItem()] 75 | ) 76 | 77 | groupWithBigElement.contentInsets = .init(top: 0, leading: 2, bottom: 4, trailing: 2) 78 | 79 | 80 | let compositionalGroup = NSCollectionLayoutGroup.vertical( 81 | layoutSize: .init( 82 | widthDimension: .fractionalWidth(1), 83 | heightDimension: .fractionalWidth(1.5) 84 | ), 85 | subitems: [group, groupWithBigElement] 86 | ) 87 | 88 | return compositionalGroup 89 | } 90 | 91 | private static func makeSectionHeader() -> NSCollectionLayoutBoundarySupplementaryItem { 92 | return NSCollectionLayoutBoundarySupplementaryItem( 93 | layoutSize: .init( 94 | widthDimension: .fractionalWidth(1), 95 | heightDimension: .absolute(32) 96 | ), 97 | elementKind: SupplementaryElements.sectionHeader, 98 | alignment: .top 99 | ) 100 | } 101 | 102 | private static func makeCollectionHeader() -> NSCollectionLayoutBoundarySupplementaryItem { 103 | return NSCollectionLayoutBoundarySupplementaryItem( 104 | layoutSize: .init( 105 | widthDimension: .fractionalWidth(1), 106 | heightDimension: .absolute(32) 107 | ), 108 | elementKind: SupplementaryElements.collectionHeader, 109 | alignment: .top 110 | ) 111 | } 112 | 113 | private static func makeSpacer() -> NSCollectionLayoutBoundarySupplementaryItem { 114 | return NSCollectionLayoutBoundarySupplementaryItem( 115 | layoutSize: .init( 116 | widthDimension: .fractionalWidth(1), 117 | heightDimension: .absolute(60) 118 | ), 119 | elementKind: SupplementaryElements.sectionSpacer, 120 | alignment: .top 121 | ) 122 | } 123 | 124 | private static func makeSection() -> NSCollectionLayoutSection { 125 | let section = NSCollectionLayoutSection(group: makeGroup()) 126 | section.contentInsets = .init( 127 | top: 16, 128 | leading: 0, 129 | bottom: 0, trailing: 0 130 | ) 131 | section.boundarySupplementaryItems = [makeSpacer(), makeSectionHeader()] 132 | 133 | return section 134 | } 135 | 136 | } 137 | 138 | extension GridCompositionalLayout { 139 | 140 | private static func makeLetterItem() -> NSCollectionLayoutItem { 141 | let item = NSCollectionLayoutItem( 142 | layoutSize: .init( 143 | widthDimension: .fractionalWidth(1), 144 | heightDimension: .fractionalHeight(0.5) 145 | ) 146 | ) 147 | 148 | item.contentInsets = .init(top: 3, leading: 3, bottom: 3, trailing: 3) 149 | return item 150 | } 151 | 152 | private static func makeLetterGroup() -> NSCollectionLayoutGroup { 153 | let group = NSCollectionLayoutGroup.vertical( 154 | layoutSize: .init( 155 | widthDimension: .fractionalWidth(3/8), 156 | heightDimension: .fractionalWidth(6/8) 157 | ), 158 | subitems: [makeLetterItem()] 159 | ) 160 | 161 | return group 162 | } 163 | 164 | private static func makeLetterSection() -> NSCollectionLayoutSection { 165 | let section = NSCollectionLayoutSection(group: makeLetterGroup()) 166 | section.contentInsets = .init( 167 | top: 16, 168 | leading: 0, 169 | bottom: 16, 170 | trailing: 0 171 | ) 172 | section.orthogonalScrollingBehavior = .groupPagingCentered 173 | return section 174 | 175 | } 176 | 177 | } 178 | -------------------------------------------------------------------------------- /compositionalLayout/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIApplicationSceneManifest 6 | 7 | UIApplicationSupportsMultipleScenes 8 | 9 | UISceneConfigurations 10 | 11 | UIWindowSceneSessionRoleApplication 12 | 13 | 14 | UISceneConfigurationName 15 | Default Configuration 16 | UISceneDelegateClassName 17 | $(PRODUCT_MODULE_NAME).SceneDelegate 18 | UISceneStoryboardFile 19 | Main 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /compositionalLayout/Model.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Model.swift 3 | // compositionalLayout 4 | // 5 | // Created by Artur Gruchała on 26/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | extension UIColor { 11 | static var random: UIColor { 12 | return UIColor( 13 | red: .random(in: 0...1), 14 | green: .random(in: 0...1), 15 | blue: .random(in: 0...1), 16 | alpha: 1.0 17 | ) 18 | } 19 | } 20 | 21 | final class ColorRepository { 22 | lazy var colors: [UIColor] = { 23 | (0...100).map { _ in 24 | UIColor.random 25 | } 26 | }() 27 | 28 | lazy var letters: [Character] = { 29 | let aScalars = "a".unicodeScalars 30 | let aCode = aScalars[aScalars.startIndex].value 31 | 32 | return (0..<26).map { i in 33 | Character(Unicode.Scalar(aCode + i) ?? aScalars[aScalars.startIndex]) 34 | } 35 | }() 36 | } 37 | -------------------------------------------------------------------------------- /compositionalLayout/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // compositionalLayout 4 | // 5 | // Created by Artur Gruchała on 26/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | guard let _ = (scene as? UIWindowScene) else { return } 20 | } 21 | 22 | func sceneDidDisconnect(_ scene: UIScene) { 23 | // Called as the scene is being released by the system. 24 | // This occurs shortly after the scene enters the background, or when its session is discarded. 25 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 26 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 27 | } 28 | 29 | func sceneDidBecomeActive(_ scene: UIScene) { 30 | // Called when the scene has moved from an inactive state to an active state. 31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 32 | } 33 | 34 | func sceneWillResignActive(_ scene: UIScene) { 35 | // Called when the scene will move from an active state to an inactive state. 36 | // This may occur due to temporary interruptions (ex. an incoming phone call). 37 | } 38 | 39 | func sceneWillEnterForeground(_ scene: UIScene) { 40 | // Called as the scene transitions from the background to the foreground. 41 | // Use this method to undo the changes made on entering the background. 42 | } 43 | 44 | func sceneDidEnterBackground(_ scene: UIScene) { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /compositionalLayout/SupplementaryViews.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SuplementaryViews.swift 3 | // compositionalLayout 4 | // 5 | // Created by Artur Gruchała on 26/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | final class HeaderView: UICollectionReusableView { 11 | private(set) lazy var label = UILabel() 12 | 13 | required init?(coder: NSCoder) { 14 | super.init(coder: coder) 15 | } 16 | 17 | override init(frame: CGRect) { 18 | super.init(frame: frame) 19 | label.translatesAutoresizingMaskIntoConstraints = false 20 | addSubview(label) 21 | 22 | NSLayoutConstraint.activate( 23 | [ 24 | label.centerXAnchor.constraint(equalTo: self.centerXAnchor), 25 | label.centerYAnchor.constraint(equalTo: self.centerYAnchor) 26 | ] 27 | ) 28 | } 29 | } 30 | 31 | 32 | final class Spacer: UICollectionReusableView { 33 | required init?(coder: NSCoder) { 34 | super.init(coder: coder) 35 | } 36 | 37 | override init(frame: CGRect) { 38 | super.init(frame: frame) 39 | backgroundColor = .clear 40 | } 41 | } 42 | 43 | final class LetterCell: UICollectionViewCell { 44 | private(set) lazy var letterLabel = UILabel() 45 | 46 | override init(frame: CGRect) { 47 | super.init(frame: frame) 48 | setupViews() 49 | } 50 | 51 | required init?(coder: NSCoder) { 52 | super.init(coder: coder) 53 | } 54 | 55 | private func setupViews() { 56 | contentView.addSubview(letterLabel) 57 | letterLabel.translatesAutoresizingMaskIntoConstraints = false 58 | 59 | layer.borderWidth = 2 60 | layer.borderColor = UIColor.black.cgColor 61 | layer.cornerRadius = 5 62 | 63 | NSLayoutConstraint.activate( 64 | [ 65 | letterLabel.centerXAnchor.constraint(equalTo: contentView.centerXAnchor), 66 | letterLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor) 67 | ] 68 | ) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /compositionalLayout/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // compositionalLayout 4 | // 5 | // Created by Artur Gruchała on 26/09/2022. 6 | // 7 | 8 | import UIKit 9 | 10 | class ViewController: UIViewController { 11 | 12 | private lazy var collectionView = UICollectionView( 13 | frame: .zero, 14 | collectionViewLayout: GridCompositionalLayout.generateLayout() 15 | ) 16 | 17 | private lazy var model = ColorRepository() 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | prepareCollectionView() 22 | } 23 | 24 | private func prepareCollectionView() { 25 | collectionView.dataSource = self 26 | collectionView.translatesAutoresizingMaskIntoConstraints = false 27 | 28 | collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell") 29 | collectionView.register(LetterCell.self, forCellWithReuseIdentifier: "letterCell") 30 | 31 | collectionView.register( 32 | HeaderView.self, 33 | forSupplementaryViewOfKind: SupplementaryElements.collectionHeader, 34 | withReuseIdentifier: SupplementaryElements.collectionHeader 35 | ) 36 | 37 | collectionView.register( 38 | HeaderView.self, 39 | forSupplementaryViewOfKind: SupplementaryElements.sectionHeader, 40 | withReuseIdentifier: SupplementaryElements.sectionHeader 41 | ) 42 | 43 | collectionView.register( 44 | Spacer.self, 45 | forSupplementaryViewOfKind: SupplementaryElements.sectionSpacer, 46 | withReuseIdentifier: SupplementaryElements.sectionSpacer 47 | ) 48 | 49 | 50 | view.addSubview(collectionView) 51 | 52 | NSLayoutConstraint.activate( 53 | [ 54 | collectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), 55 | collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor), 56 | collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 57 | collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor) 58 | ] 59 | ) 60 | } 61 | } 62 | 63 | extension ViewController: UICollectionViewDataSource { 64 | func numberOfSections(in collectionView: UICollectionView) -> Int { 65 | return 2 66 | } 67 | 68 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 69 | if section % 2 == 0 { 70 | return model.letters.count 71 | } 72 | return model.colors.count 73 | } 74 | 75 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 76 | if indexPath.section % 2 == 0 { 77 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "letterCell", for: indexPath) as! LetterCell 78 | cell.letterLabel.text = String(model.letters[indexPath.row]) 79 | return cell 80 | } 81 | 82 | 83 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) 84 | cell.backgroundColor = model.colors[indexPath.row] 85 | cell.layer.cornerRadius = 5 86 | cell.layer.masksToBounds = true 87 | return cell 88 | } 89 | 90 | func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 91 | let cell = collectionView.dequeueReusableSupplementaryView( 92 | ofKind: kind, 93 | withReuseIdentifier: kind, 94 | for: indexPath 95 | ) 96 | 97 | if let header = cell as? HeaderView { 98 | header.label.text = kind 99 | } 100 | 101 | return cell 102 | } 103 | } 104 | 105 | --------------------------------------------------------------------------------