diff --git a/examples/CustomCollectionView-Swift/Podfile b/examples/CustomCollectionView-Swift/Podfile new file mode 100644 index 0000000000..5af5c3acf4 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Podfile @@ -0,0 +1,10 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +target 'Sample' do + # Comment this line if you're not using Swift and don't want to use dynamic frameworks + use_frameworks! + + # Pods for CustomCollectionView + pod 'AsyncDisplayKit', :git => 'https://github.com/facebook/AsyncDisplayKit.git', :tag => '2.0-beta.1' +end diff --git a/examples/CustomCollectionView-Swift/Sample.xcodeproj/project.pbxproj b/examples/CustomCollectionView-Swift/Sample.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..186ac5b21e --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample.xcodeproj/project.pbxproj @@ -0,0 +1,395 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 27F2D2683285DCB73EE734BB /* Pods_Sample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7DA4A9952245B7E9BA8201F /* Pods_Sample.framework */; }; + 5D823AD51DD3B7770075E14A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D823AD41DD3B7770075E14A /* AppDelegate.swift */; }; + 5D823AD71DD3B7770075E14A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D823AD61DD3B7770075E14A /* ViewController.swift */; }; + 5D823ADA1DD3B7770075E14A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5D823AD81DD3B7770075E14A /* Main.storyboard */; }; + 5D823ADC1DD3B7770075E14A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5D823ADB1DD3B7770075E14A /* Assets.xcassets */; }; + 5D823ADF1DD3B7770075E14A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5D823ADD1DD3B7770075E14A /* LaunchScreen.storyboard */; }; + 5D823AE71DD3B7D30075E14A /* MosaicCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D823AE61DD3B7D30075E14A /* MosaicCollectionViewLayout.swift */; }; + 5D823AE91DD3B7D70075E14A /* ImageCellNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D823AE81DD3B7D70075E14A /* ImageCellNode.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 5D823AD11DD3B7770075E14A /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 5D823AD41DD3B7770075E14A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 5D823AD61DD3B7770075E14A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 5D823AD91DD3B7770075E14A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 5D823ADB1DD3B7770075E14A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 5D823ADE1DD3B7770075E14A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 5D823AE01DD3B7770075E14A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 5D823AE61DD3B7D30075E14A /* MosaicCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MosaicCollectionViewLayout.swift; sourceTree = ""; }; + 5D823AE81DD3B7D70075E14A /* ImageCellNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCellNode.swift; sourceTree = ""; }; + 73F1C0E45062A0A8CDC033A1 /* Pods-Sample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Sample.release.xcconfig"; path = "Pods/Target Support Files/Pods-Sample/Pods-Sample.release.xcconfig"; sourceTree = ""; }; + A9E9A143FF858FD89A482A84 /* Pods-Sample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Sample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Sample/Pods-Sample.debug.xcconfig"; sourceTree = ""; }; + F7DA4A9952245B7E9BA8201F /* Pods_Sample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Sample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5D823ACE1DD3B7770075E14A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 27F2D2683285DCB73EE734BB /* Pods_Sample.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 3A21D910663270E99063573E /* Pods */ = { + isa = PBXGroup; + children = ( + A9E9A143FF858FD89A482A84 /* Pods-Sample.debug.xcconfig */, + 73F1C0E45062A0A8CDC033A1 /* Pods-Sample.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; + 5D823AC81DD3B7760075E14A = { + isa = PBXGroup; + children = ( + 5D823AD31DD3B7770075E14A /* Sample */, + 5D823AD21DD3B7770075E14A /* Products */, + 3A21D910663270E99063573E /* Pods */, + 728C7877715727493EFEE42D /* Frameworks */, + ); + sourceTree = ""; + }; + 5D823AD21DD3B7770075E14A /* Products */ = { + isa = PBXGroup; + children = ( + 5D823AD11DD3B7770075E14A /* Sample.app */, + ); + name = Products; + sourceTree = ""; + }; + 5D823AD31DD3B7770075E14A /* Sample */ = { + isa = PBXGroup; + children = ( + 5D823AD41DD3B7770075E14A /* AppDelegate.swift */, + 5D823AD61DD3B7770075E14A /* ViewController.swift */, + 5D823AE81DD3B7D70075E14A /* ImageCellNode.swift */, + 5D823AE61DD3B7D30075E14A /* MosaicCollectionViewLayout.swift */, + 5D823AD81DD3B7770075E14A /* Main.storyboard */, + 5D823ADB1DD3B7770075E14A /* Assets.xcassets */, + 5D823ADD1DD3B7770075E14A /* LaunchScreen.storyboard */, + 5D823AE01DD3B7770075E14A /* Info.plist */, + ); + path = Sample; + sourceTree = ""; + }; + 728C7877715727493EFEE42D /* Frameworks */ = { + isa = PBXGroup; + children = ( + F7DA4A9952245B7E9BA8201F /* Pods_Sample.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5D823AD01DD3B7770075E14A /* Sample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5D823AE31DD3B7770075E14A /* Build configuration list for PBXNativeTarget "Sample" */; + buildPhases = ( + BAA73690D42731AA5D8001CF /* [CP] Check Pods Manifest.lock */, + 5D823ACD1DD3B7770075E14A /* Sources */, + 5D823ACE1DD3B7770075E14A /* Frameworks */, + 5D823ACF1DD3B7770075E14A /* Resources */, + 8293091514A70C5E7E487A36 /* [CP] Embed Pods Frameworks */, + 641DF857294FFEAA1878D05C /* [CP] Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Sample; + productName = Sample; + productReference = 5D823AD11DD3B7770075E14A /* Sample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 5D823AC91DD3B7760075E14A /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0810; + LastUpgradeCheck = 0810; + ORGANIZATIONNAME = AsyncDisplayKit; + TargetAttributes = { + 5D823AD01DD3B7770075E14A = { + CreatedOnToolsVersion = 8.1; + DevelopmentTeam = 888KTQ92ZP; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 5D823ACC1DD3B7760075E14A /* Build configuration list for PBXProject "Sample" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 5D823AC81DD3B7760075E14A; + productRefGroup = 5D823AD21DD3B7770075E14A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5D823AD01DD3B7770075E14A /* Sample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 5D823ACF1DD3B7770075E14A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5D823ADF1DD3B7770075E14A /* LaunchScreen.storyboard in Resources */, + 5D823ADC1DD3B7770075E14A /* Assets.xcassets in Resources */, + 5D823ADA1DD3B7770075E14A /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 641DF857294FFEAA1878D05C /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Sample/Pods-Sample-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 8293091514A70C5E7E487A36 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Sample/Pods-Sample-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + BAA73690D42731AA5D8001CF /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 5D823ACD1DD3B7770075E14A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5D823AE71DD3B7D30075E14A /* MosaicCollectionViewLayout.swift in Sources */, + 5D823AD71DD3B7770075E14A /* ViewController.swift in Sources */, + 5D823AD51DD3B7770075E14A /* AppDelegate.swift in Sources */, + 5D823AE91DD3B7D70075E14A /* ImageCellNode.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 5D823AD81DD3B7770075E14A /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 5D823AD91DD3B7770075E14A /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 5D823ADD1DD3B7770075E14A /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 5D823ADE1DD3B7770075E14A /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 5D823AE11DD3B7770075E14A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 5D823AE21DD3B7770075E14A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 5D823AE41DD3B7770075E14A /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = A9E9A143FF858FD89A482A84 /* Pods-Sample.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 888KTQ92ZP; + INFOPLIST_FILE = Sample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.facebook.AsyncDisplayKit.Sample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + 5D823AE51DD3B7770075E14A /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 73F1C0E45062A0A8CDC033A1 /* Pods-Sample.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 888KTQ92ZP; + INFOPLIST_FILE = Sample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.facebook.AsyncDisplayKit.Sample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5D823ACC1DD3B7760075E14A /* Build configuration list for PBXProject "Sample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5D823AE11DD3B7770075E14A /* Debug */, + 5D823AE21DD3B7770075E14A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5D823AE31DD3B7770075E14A /* Build configuration list for PBXNativeTarget "Sample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5D823AE41DD3B7770075E14A /* Debug */, + 5D823AE51DD3B7770075E14A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 5D823AC91DD3B7760075E14A /* Project object */; +} diff --git a/examples/CustomCollectionView-Swift/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/examples/CustomCollectionView-Swift/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..a80c038249 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/examples/CustomCollectionView-Swift/Sample/AppDelegate.swift b/examples/CustomCollectionView-Swift/Sample/AppDelegate.swift new file mode 100644 index 0000000000..13e0670d1b --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/AppDelegate.swift @@ -0,0 +1,57 @@ +// +// AppDelegate.swift +// Sample +// +// Created by Rajeev Gupta on 11/9/16. +// +// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(_ application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..b8236c6534 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,48 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/Contents.json new file mode 100644 index 0000000000..da4a164c91 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_0.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_0.imageset/Contents.json new file mode 100644 index 0000000000..09ec0851ee --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_0.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_0.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_0.imageset/image_0.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_0.imageset/image_0.jpg new file mode 100644 index 0000000000..4a365897ea Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_0.imageset/image_0.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_1.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_1.imageset/Contents.json new file mode 100644 index 0000000000..6d2e9f5f7c --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_1.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_1.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_1.imageset/image_1.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_1.imageset/image_1.jpg new file mode 100644 index 0000000000..5cb4828f44 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_1.imageset/image_1.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_10.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_10.imageset/Contents.json new file mode 100644 index 0000000000..ea10700189 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_10.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_10.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_10.imageset/image_10.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_10.imageset/image_10.jpg new file mode 100644 index 0000000000..ea5cd6d268 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_10.imageset/image_10.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_11.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_11.imageset/Contents.json new file mode 100644 index 0000000000..dc85469057 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_11.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_11.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_11.imageset/image_11.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_11.imageset/image_11.jpg new file mode 100644 index 0000000000..e93c68e512 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_11.imageset/image_11.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_12.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_12.imageset/Contents.json new file mode 100644 index 0000000000..a6d99003d1 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_12.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_12.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_12.imageset/image_12.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_12.imageset/image_12.jpg new file mode 100644 index 0000000000..d520b6d80f Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_12.imageset/image_12.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_13.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_13.imageset/Contents.json new file mode 100644 index 0000000000..4eb6baad3b --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_13.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_13.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_13.imageset/image_13.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_13.imageset/image_13.jpg new file mode 100644 index 0000000000..c0232370cd Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_13.imageset/image_13.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_2.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_2.imageset/Contents.json new file mode 100644 index 0000000000..b2536e53de --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_2.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_2.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_2.imageset/image_2.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_2.imageset/image_2.jpg new file mode 100644 index 0000000000..175343454d Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_2.imageset/image_2.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_3.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_3.imageset/Contents.json new file mode 100644 index 0000000000..512e735090 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_3.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_3.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_3.imageset/image_3.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_3.imageset/image_3.jpg new file mode 100644 index 0000000000..f5398cac79 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_3.imageset/image_3.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_4.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_4.imageset/Contents.json new file mode 100644 index 0000000000..88b2b7b98a --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_4.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_4.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_4.imageset/image_4.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_4.imageset/image_4.jpg new file mode 100644 index 0000000000..2a6fe4c264 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_4.imageset/image_4.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_5.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_5.imageset/Contents.json new file mode 100644 index 0000000000..1f24c086d9 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_5.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_5.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_5.imageset/image_5.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_5.imageset/image_5.jpg new file mode 100644 index 0000000000..4e507b8064 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_5.imageset/image_5.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_6.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_6.imageset/Contents.json new file mode 100644 index 0000000000..25f33f2acd --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_6.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_6.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_6.imageset/image_6.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_6.imageset/image_6.jpg new file mode 100644 index 0000000000..35fe778b3a Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_6.imageset/image_6.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_7.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_7.imageset/Contents.json new file mode 100644 index 0000000000..5fdd6ba2cf --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_7.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_7.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_7.imageset/image_7.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_7.imageset/image_7.jpg new file mode 100644 index 0000000000..8f5e037722 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_7.imageset/image_7.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_8.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_8.imageset/Contents.json new file mode 100644 index 0000000000..563d5ba824 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_8.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_8.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_8.imageset/image_8.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_8.imageset/image_8.jpg new file mode 100644 index 0000000000..5651436bb6 Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_8.imageset/image_8.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_9.imageset/Contents.json b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_9.imageset/Contents.json new file mode 100644 index 0000000000..66c1b859b1 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_9.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "image_9.jpg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_9.imageset/image_9.jpg b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_9.imageset/image_9.jpg new file mode 100644 index 0000000000..9fb6e47d3f Binary files /dev/null and b/examples/CustomCollectionView-Swift/Sample/Assets.xcassets/image_9.imageset/image_9.jpg differ diff --git a/examples/CustomCollectionView-Swift/Sample/Base.lproj/LaunchScreen.storyboard b/examples/CustomCollectionView-Swift/Sample/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000..fdf3f97d1b --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/CustomCollectionView-Swift/Sample/Base.lproj/Main.storyboard b/examples/CustomCollectionView-Swift/Sample/Base.lproj/Main.storyboard new file mode 100644 index 0000000000..273375fc70 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/CustomCollectionView-Swift/Sample/ImageCellNode.swift b/examples/CustomCollectionView-Swift/Sample/ImageCellNode.swift new file mode 100644 index 0000000000..52f8fdb55f --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/ImageCellNode.swift @@ -0,0 +1,51 @@ +// +// ImageCellNode.swift +// Sample +// +// Created by Rajeev Gupta on 11/9/16. +// +// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import UIKit +import AsyncDisplayKit + +class ImageCellNode: ASCellNode { + let imageNode = ASImageNode() + required init(with image : UIImage) { + super.init() + imageNode.image = image + self.addSubnode(self.imageNode) + } + + override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec { + let imageSize = imageNode.image?.size + print("imageNode= \(imageNode.bounds), image=\(imageSize)") + + var imageRatio: CGFloat = 0.5 + if imageNode.image != nil { + imageRatio = (imageNode.image?.size.height)! / (imageNode.image?.size.width)! + } + + let imagePlace = ASRatioLayoutSpec(ratio: imageRatio, child: imageNode) + + let stackLayout = ASStackLayoutSpec.horizontal() + stackLayout.justifyContent = .start + stackLayout.alignItems = .start + stackLayout.style.flexShrink = 1.0 + stackLayout.children = [imagePlace] + + return ASInsetLayoutSpec(insets: UIEdgeInsets.zero, child: stackLayout) + } + +} diff --git a/examples/CustomCollectionView-Swift/Sample/Info.plist b/examples/CustomCollectionView-Swift/Sample/Info.plist new file mode 100644 index 0000000000..38e98af23d --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/Info.plist @@ -0,0 +1,38 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift b/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift new file mode 100644 index 0000000000..2eecd4731b --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift @@ -0,0 +1,252 @@ +// +// MosaicCollectionViewLayout +// Sample +// +// Created by Rajeev Gupta on 11/9/16. +// +// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import Foundation +import UIKit +import AsyncDisplayKit + +protocol MosaicCollectionViewLayoutDelegate: ASCollectionDelegate { + func collectionView(_ collectionView: UICollectionView, layout: MosaicCollectionViewLayout, originalItemSizeAtIndexPath: IndexPath) -> CGSize +} + +class MosaicCollectionViewLayout: UICollectionViewFlowLayout { + var numberOfColumns: Int + var columnSpacing: CGFloat + var _sectionInset: UIEdgeInsets + var interItemSpacing: UIEdgeInsets + var headerHeight: CGFloat + var _columnHeights: [[CGFloat]]? + var _itemAttributes = [[UICollectionViewLayoutAttributes]]() + var _headerAttributes = [UICollectionViewLayoutAttributes]() + var _allAttributes = [UICollectionViewLayoutAttributes]() + + required override init() { + self.numberOfColumns = 2 + self.columnSpacing = 10.0 + self.headerHeight = 44.0 //viewcontroller + self._sectionInset = UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0) + self.interItemSpacing = UIEdgeInsetsMake(10.0, 0, 10.0, 0) + super.init() + self.scrollDirection = .vertical + } + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public var delegate : MosaicCollectionViewLayoutDelegate? + + override func prepare() { + super.prepare() + guard let collectionView = self.collectionView else { return } + + _itemAttributes = [] + _allAttributes = [] + _headerAttributes = [] + _columnHeights = [] + + var top: CGFloat = 0 + + let numberOfSections: NSInteger = collectionView.numberOfSections + + for section in 0 ..< numberOfSections { + let numberOfItems = collectionView.numberOfItems(inSection: section) + + top += _sectionInset.top + + if (headerHeight > 0) { + let headerSize: CGSize = self._headerSizeForSection(section: section) + + let attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, with: NSIndexPath(row: 0, section: section) as IndexPath) + + attributes.frame = CGRect(x: _sectionInset.left, y: top, width: headerSize.width, height: headerSize.height) + _headerAttributes.append(attributes) + _allAttributes.append(attributes) + top = attributes.frame.maxY + } + + _columnHeights?.append([]) //Adding new Section + for _ in 0 ..< self.numberOfColumns { + self._columnHeights?[section].append(top) + } + + let columnWidth = self._columnWidthForSection(section: section) + _itemAttributes.append([]) + for idx in 0 ..< numberOfItems { + let columnIndex: Int = self._shortestColumnIndexInSection(section: section) + let indexPath = IndexPath(item: idx, section: section) + + let itemSize = self._itemSizeAtIndexPath(indexPath: indexPath); + let xOffset = _sectionInset.left + (columnWidth + columnSpacing) * CGFloat(columnIndex) + let yOffset = _columnHeights![section][columnIndex] + + let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath) + + attributes.frame = CGRect(x: xOffset, y: yOffset, width: itemSize.width, height: itemSize.height) + + _columnHeights?[section][columnIndex] = attributes.frame.maxY + interItemSpacing.bottom + + _itemAttributes[section].append(attributes) + _allAttributes.append(attributes) + } + + let columnIndex: Int = self._tallestColumnIndexInSection(section: section) + top = (_columnHeights?[section][columnIndex])! - interItemSpacing.bottom + _sectionInset.bottom + + for idx in 0 ..< _columnHeights![section].count { + _columnHeights![section][idx] = top + } + } + } + + override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? + { + var includedAttributes: [UICollectionViewLayoutAttributes] = [] + // Slow search for small batches + for attribute in _allAttributes { + if (attribute.frame.intersects(rect)) { + includedAttributes.append(attribute) + } + } + return includedAttributes + } + + override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? + { + guard indexPath.section < _itemAttributes.count, + indexPath.item < _itemAttributes[indexPath.section].count + else { + return nil + } + return _itemAttributes[indexPath.section][indexPath.item] + } + + override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? + { + if (elementKind == UICollectionElementKindSectionHeader) { + return _headerAttributes[indexPath.section] + } + return nil + } + + override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { + if (!(self.collectionView?.bounds.size.equalTo(newBounds.size))!) { + return true; + } + return false; + } + + func _widthForSection (section: Int) -> CGFloat + { + return self.collectionView!.bounds.size.width - _sectionInset.left - _sectionInset.right; + } + + func _columnWidthForSection(section: Int) -> CGFloat + { + return (self._widthForSection(section: section) - ((CGFloat(numberOfColumns - 1)) * columnSpacing)) / CGFloat(numberOfColumns) + } + + func _itemSizeAtIndexPath(indexPath: IndexPath) -> CGSize + { + var size = CGSize(width: self._columnWidthForSection(section: indexPath.section), height: 0) + let originalSize = self.delegate!.collectionView(self.collectionView!, layout:self, originalItemSizeAtIndexPath:indexPath) + if (originalSize.height > 0 && originalSize.width > 0) { + size.height = originalSize.height / originalSize.width * size.width + } + return size + } + + func _headerSizeForSection(section: Int) -> CGSize + { + return CGSize(width: self._widthForSection(section: section), height: headerHeight) + } + + override var collectionViewContentSize: CGSize + { + var height: CGFloat = 0 + if ((_columnHeights?.count)! > 0) { + if (_columnHeights?[(_columnHeights?.count)!-1].count)! > 0 { + height = (_columnHeights?[(_columnHeights?.count)!-1][0])! + } + } + return CGSize(width: self.collectionView!.bounds.size.width, height: height) + } + + func _tallestColumnIndexInSection(section: Int) -> Int + { + var index: Int = 0; + var tallestHeight: CGFloat = 0; + _ = _columnHeights?[section].enumerated().map { (idx,height) in + if (height > tallestHeight) { + index = idx; + tallestHeight = height + } + } + return index + } + + func _shortestColumnIndexInSection(section: Int) -> Int + { + var index: Int = 0; + var shortestHeight: CGFloat = CGFloat.greatestFiniteMagnitude + _ = _columnHeights?[section].enumerated().map { (idx,height) in + if (height < shortestHeight) { + index = idx; + shortestHeight = height + } + } + return index + } + +} + +class MosaicCollectionViewLayoutInspector: NSObject, ASCollectionViewLayoutInspecting +{ + func collectionView(_ collectionView: ASCollectionView, constrainedSizeForNodeAt indexPath: IndexPath) -> ASSizeRange { + let layout = collectionView.collectionViewLayout as! MosaicCollectionViewLayout + return ASSizeRangeMake(CGSize.zero, layout._itemSizeAtIndexPath(indexPath: indexPath)) + } + + func collectionView(_ collectionView: ASCollectionView, constrainedSizeForSupplementaryNodeOfKind: String, at atIndexPath: IndexPath) -> ASSizeRange + { + let layout = collectionView.collectionViewLayout as! MosaicCollectionViewLayout + return ASSizeRange.init(min: CGSize.zero, max: layout._headerSizeForSection(section: atIndexPath.section)) + } + + /** + * Asks the inspector for the number of supplementary sections in the collection view for the given kind. + */ + func collectionView(_ collectionView: ASCollectionView, numberOfSectionsForSupplementaryNodeOfKind kind: String) -> UInt { + if (kind == UICollectionElementKindSectionHeader) { + return UInt((collectionView.dataSource?.numberOfSections!(in: collectionView))!) + } else { + return 0 + } + } + + /** + * Asks the inspector for the number of supplementary views for the given kind in the specified section. + */ + func collectionView(_ collectionView: ASCollectionView, supplementaryNodesOfKind kind: String, inSection section: UInt) -> UInt { + if (kind == UICollectionElementKindSectionHeader) { + return 1 + } else { + return 0 + } + } +} diff --git a/examples/CustomCollectionView-Swift/Sample/ViewController.swift b/examples/CustomCollectionView-Swift/Sample/ViewController.swift new file mode 100644 index 0000000000..c325f8bc27 --- /dev/null +++ b/examples/CustomCollectionView-Swift/Sample/ViewController.swift @@ -0,0 +1,101 @@ +// +// ViewController.swift +// Sample +// +// Created by Rajeev Gupta on 11/9/16. +// +// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import UIKit +import AsyncDisplayKit + +class ViewController: UIViewController, MosaicCollectionViewLayoutDelegate, ASCollectionDataSource, ASCollectionDelegate { + + var _sections = [[UIImage]]() + let _collectionNode: ASCollectionNode! + let _layoutInspector = MosaicCollectionViewLayoutInspector() + let kNumberOfImages: UInt = 14 + + required init?(coder aDecoder: NSCoder) { + let layout = MosaicCollectionViewLayout() + layout.numberOfColumns = 3; + layout.headerHeight = 44; + _collectionNode = ASCollectionNode(frame: CGRect.zero, collectionViewLayout: layout) + super.init(coder: aDecoder) + layout.delegate = self + + _sections.append([]); + var section = 0 + for idx in 0 ..< kNumberOfImages { + let name = String(format: "image_%d.jpg", idx) + _sections[section].append(UIImage(named: name)!) + if ((idx + 1) % 5 == 0 && idx < kNumberOfImages - 1) { + section += 1 + _sections.append([]) + } + } + + _collectionNode.dataSource = self; + _collectionNode.delegate = self; + _collectionNode.view.layoutInspector = _layoutInspector + _collectionNode.backgroundColor = UIColor.white + _collectionNode.view.isScrollEnabled = true + _collectionNode.registerSupplementaryNode(ofKind: UICollectionElementKindSectionHeader) + } + + deinit { + _collectionNode.dataSource = nil; + _collectionNode.delegate = nil; + } + + override func viewDidLoad() { + super.viewDidLoad() + self.view.addSubnode(_collectionNode!) + } + + override func viewWillLayoutSubviews() { + _collectionNode.frame = self.view.bounds; + } + + func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode { + let image = _sections[indexPath.section][indexPath.item] + return ImageCellNode(with: image) + } + + + func collectionNode(_ collectionNode: ASCollectionNode, nodeForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> ASCellNode { + let textAttributes : NSDictionary = [ + NSFontAttributeName: UIFont.preferredFont(forTextStyle: UIFontTextStyle.headline), + NSForegroundColorAttributeName: UIColor.gray + ] + let textInsets = UIEdgeInsets(top: 11, left: 0, bottom: 11, right: 0) + let textCellNode = ASTextCellNode(attributes: textAttributes as! [AnyHashable : Any], insets: textInsets) + textCellNode.text = String(format: "Section %zd", indexPath.section + 1) + return textCellNode; + } + + + func numberOfSections(in collectionNode: ASCollectionNode) -> Int { + return _sections.count + } + + func collectionNode(_ collectionNode: ASCollectionNode, numberOfItemsInSection section: Int) -> Int { + return _sections[section].count + } + + internal func collectionView(_ collectionView: UICollectionView, layout: MosaicCollectionViewLayout, originalItemSizeAtIndexPath: IndexPath) -> CGSize { + return _sections[originalItemSizeAtIndexPath.section][originalItemSizeAtIndexPath.item].size + } +} +