Add 'submodules/AsyncDisplayKit/' from commit '02bedc12816e251ad71777f9d2578329b6d2bef6'
git-subtree-dir: submodules/AsyncDisplayKit git-subtree-mainline:d06f423e0egit-subtree-split:02bedc1281
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
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.
|
||||
let window = UIWindow(frame: UIScreen.main.bounds)
|
||||
window.backgroundColor = .white
|
||||
window.rootViewController = ViewController()
|
||||
window.makeKeyAndVisible()
|
||||
|
||||
self.window = window
|
||||
|
||||
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:.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.2 MiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 114 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 516 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 434 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 78 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 168 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 540 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.1 MiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 111 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 892 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 494 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 250 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 98 KiB |
@@ -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"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 429 KiB |
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// ImageCellNode.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,246 @@
|
||||
//
|
||||
// MosaicCollectionViewLayout.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
func scrollableDirections() -> ASScrollDirection {
|
||||
return ASScrollDirectionVerticalDirections;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
|
||||
class ViewController: ASViewController<ASCollectionNode>, MosaicCollectionViewLayoutDelegate, ASCollectionDataSource, ASCollectionDelegate {
|
||||
|
||||
var _sections = [[UIImage]]()
|
||||
let _collectionNode: ASCollectionNode
|
||||
let _layoutInspector = MosaicCollectionViewLayoutInspector()
|
||||
let kNumberOfImages: UInt = 14
|
||||
|
||||
init() {
|
||||
let layout = MosaicCollectionViewLayout()
|
||||
layout.numberOfColumns = 3;
|
||||
layout.headerHeight = 44;
|
||||
_collectionNode = ASCollectionNode(frame: CGRect.zero, collectionViewLayout: layout)
|
||||
super.init(node: _collectionNode)
|
||||
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.backgroundColor = UIColor.white
|
||||
_collectionNode.dataSource = self
|
||||
_collectionNode.delegate = self
|
||||
_collectionNode.layoutInspector = _layoutInspector
|
||||
_collectionNode.registerSupplementaryNode(ofKind: UICollectionElementKindSectionHeader)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
_collectionNode.view.isScrollEnabled = true
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||