Skip to content

Commit

Permalink
Simplify tvOS layout
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Mar 29, 2017
1 parent ad7ea3b commit e3358a6
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions tvOS/PhotosCollectionLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,7 @@ import UIKit
class PhotosCollectionLayout: UICollectionViewFlowLayout {
static let headerSize = CGFloat(69)
class var numberOfColumns: Int {
#if os(iOS)
var isPortrait: Bool
switch UIDevice.current.orientation {
case .portrait, .portraitUpsideDown, .unknown, .faceUp, .faceDown:
isPortrait = true
case .landscapeLeft, .landscapeRight:
isPortrait = false
}

var numberOfColumns = 0
if UIDevice.current.userInterfaceIdiom == .phone {
numberOfColumns = isPortrait ? 3 : 6
} else {
numberOfColumns = isPortrait ? 5 : 8
}

return numberOfColumns
#else
return 6
#endif
return 6
}

init(isGroupedByDay: Bool = true) {
Expand All @@ -37,26 +18,18 @@ class PhotosCollectionLayout: UICollectionViewFlowLayout {
headerReferenceSize = CGSize(width: bounds.size.width, height: PhotosCollectionLayout.headerSize)
}

#if os(tvOS)
let margin = CGFloat(25)
self.minimumLineSpacing = 50
self.minimumInteritemSpacing = margin
self.sectionInset = UIEdgeInsets(top: margin, left: margin, bottom: margin, right: margin)
#endif
let margin = CGFloat(25)
self.minimumLineSpacing = 50
self.minimumInteritemSpacing = margin
self.sectionInset = UIEdgeInsets(top: margin, left: margin, bottom: margin, right: margin)
}

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

class func itemSize() -> CGSize {
#if os(tvOS)
return CGSize(width: 260, height: 260)
#else
let bounds = UIScreen.main.bounds
let size = (bounds.width - (CGFloat(TimelineCollectionLayout.numberOfColumns) - 1)) / CGFloat(TimelineCollectionLayout.numberOfColumns)
return CGSize(width: size, height: size)
#endif
return CGSize(width: 260, height: 260)
}

func updateItemSize() {
Expand Down

0 comments on commit e3358a6

Please sign in to comment.