Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CustomCollectionView-Swift sample #22

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed crash and removed storyboard
  • Loading branch information
george-gw committed Apr 18, 2017
commit 2eb45cf8efed33227fa796b8092c4305a79070cf
12 changes: 0 additions & 12 deletions examples/CustomCollectionView-Swift/Sample.xcodeproj/project.pbxproj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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 */; };
Expand All @@ -21,7 +20,6 @@
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 = "<group>"; };
5D823AD61DD3B7770075E14A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
5D823AD91DD3B7770075E14A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
5D823ADB1DD3B7770075E14A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5D823ADE1DD3B7770075E14A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
5D823AE01DD3B7770075E14A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,7 +76,6 @@
5D823AD61DD3B7770075E14A /* ViewController.swift */,
5D823AE81DD3B7D70075E14A /* ImageCellNode.swift */,
5D823AE61DD3B7D30075E14A /* MosaicCollectionViewLayout.swift */,
5D823AD81DD3B7770075E14A /* Main.storyboard */,
5D823ADB1DD3B7770075E14A /* Assets.xcassets */,
5D823ADD1DD3B7770075E14A /* LaunchScreen.storyboard */,
5D823AE01DD3B7770075E14A /* Info.plist */,
Expand Down Expand Up @@ -159,7 +156,6 @@
files = (
5D823ADF1DD3B7770075E14A /* LaunchScreen.storyboard in Resources */,
5D823ADC1DD3B7770075E14A /* Assets.xcassets in Resources */,
5D823ADA1DD3B7770075E14A /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -228,14 +224,6 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
5D823AD81DD3B7770075E14A /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
5D823AD91DD3B7770075E14A /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
5D823ADD1DD3B7770075E14A /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down
7 changes: 7 additions & 0 deletions examples/CustomCollectionView-Swift/Sample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

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
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class ImageCellNode: ASCellNode {
}

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)!
Expand Down
2 changes: 0 additions & 2 deletions examples/CustomCollectionView-Swift/Sample/Info.plist
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
25 changes: 12 additions & 13 deletions examples/CustomCollectionView-Swift/Sample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
import UIKit
import AsyncDisplayKit

class ViewController: UIViewController, MosaicCollectionViewLayoutDelegate, ASCollectionDataSource, ASCollectionDelegate {
class ViewController: ASViewController<ASCollectionNode>, MosaicCollectionViewLayoutDelegate, ASCollectionDataSource, ASCollectionDelegate {

var _sections = [[UIImage]]()
let _collectionNode: ASCollectionNode!
let _collectionNode: ASCollectionNode
let _layoutInspector = MosaicCollectionViewLayoutInspector()
let kNumberOfImages: UInt = 14
required init?(coder aDecoder: NSCoder) {

init() {
let layout = MosaicCollectionViewLayout()
layout.numberOfColumns = 3;
layout.headerHeight = 44;
_collectionNode = ASCollectionNode(frame: CGRect.zero, collectionViewLayout: layout)
super.init(coder: aDecoder)
super.init(node: _collectionNode)
layout.delegate = self

_sections.append([]);
Expand All @@ -51,26 +51,25 @@ class ViewController: UIViewController, MosaicCollectionViewLayoutDelegate, ASCo

_collectionNode.dataSource = self;
_collectionNode.delegate = self;
_collectionNode.view.layoutInspector = _layoutInspector
_collectionNode.backgroundColor = UIColor.white
_collectionNode.view.isScrollEnabled = true
_collectionNode.registerSupplementaryNode(ofKind: UICollectionElementKindSectionHeader)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

deinit {
_collectionNode.dataSource = nil;
_collectionNode.delegate = nil;
}

override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubnode(_collectionNode!)
}

override func viewWillLayoutSubviews() {
_collectionNode.frame = self.view.bounds;
_collectionNode.view.layoutInspector = _layoutInspector
_collectionNode.view.isScrollEnabled = true
}

func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode {
let image = _sections[indexPath.section][indexPath.item]
return ImageCellNode(with: image)
Expand Down