Commit 6a42c8f2 by Daniel Dahan

reverted changes to MaterialCollection*

parent ef45d307
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
......
...@@ -59,9 +59,9 @@ public class BarView : ControlView { ...@@ -59,9 +59,9 @@ public class BarView : ControlView {
super.init(frame: frame) super.init(frame: frame)
} }
/// Basic initializer. /// Convenience initializer.
public override init() { public convenience init() {
super.init(leftControls: nil, rightControls: nil) self.init(frame: CGRectZero)
} }
/** /**
......
...@@ -75,7 +75,7 @@ public class MaterialCollectionView : UICollectionView { ...@@ -75,7 +75,7 @@ public class MaterialCollectionView : UICollectionView {
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset { public var contentInsetPreset: MaterialEdgeInset {
get { get {
return (collectionViewLayout as! MaterialCollectionViewLayout).contentInsetPreset return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset
} }
set(value) { set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset = value (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset = value
...@@ -84,20 +84,20 @@ public class MaterialCollectionView : UICollectionView { ...@@ -84,20 +84,20 @@ public class MaterialCollectionView : UICollectionView {
public override var contentInset: UIEdgeInsets { public override var contentInset: UIEdgeInsets {
get { get {
return (collectionViewLayout as! MaterialCollectionViewLayout).contentInset return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset
} }
set(value) { set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).contentInset = value (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset = value
} }
} }
/// Scroll direction. /// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection { public var scrollDirection: UICollectionViewScrollDirection {
get { get {
return (collectionViewLayout as! MaterialCollectionViewLayout).scrollDirection return (collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection
} }
set(value) { set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).scrollDirection = value (collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection = value
} }
} }
...@@ -111,20 +111,10 @@ public class MaterialCollectionView : UICollectionView { ...@@ -111,20 +111,10 @@ public class MaterialCollectionView : UICollectionView {
/// Spacing between items. /// Spacing between items.
@IBInspectable public var spacing: CGFloat { @IBInspectable public var spacing: CGFloat {
get { get {
return (collectionViewLayout as! MaterialCollectionViewLayout).spacing return (collectionViewLayout as? MaterialCollectionViewLayout)!.spacing
} }
set(value) { set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).spacing = value (collectionViewLayout as? MaterialCollectionViewLayout)!.spacing = value
}
}
/// The layout alignment direction.
public var alignmentDirection: MaterialAlignmentDirection {
get {
return (collectionViewLayout as! MaterialCollectionViewLayout).alignmentDirection
}
set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).alignmentDirection = value
} }
} }
...@@ -142,10 +132,7 @@ public class MaterialCollectionView : UICollectionView { ...@@ -142,10 +132,7 @@ public class MaterialCollectionView : UICollectionView {
- Parameter collectionViewLayout: A UICollectionViewLayout reference. - Parameter collectionViewLayout: A UICollectionViewLayout reference.
*/ */
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
guard let l = layout as? MaterialCollectionViewLayout else { super.init(frame: frame, collectionViewLayout: layout)
assert(false, "[MaterialCollectionView Error: Must use a class that subclasses MaterialCollectionViewLayout]")
}
super.init(frame: frame, collectionViewLayout: l)
prepareView() prepareView()
} }
...@@ -174,6 +161,5 @@ public class MaterialCollectionView : UICollectionView { ...@@ -174,6 +161,5 @@ public class MaterialCollectionView : UICollectionView {
contentScaleFactor = MaterialDevice.scale contentScaleFactor = MaterialDevice.scale
backgroundColor = MaterialColor.clear backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsZero contentInset = UIEdgeInsetsZero
alignmentDirection = .None
} }
} }
\ No newline at end of file
...@@ -30,16 +30,13 @@ ...@@ -30,16 +30,13 @@
import UIKit import UIKit
public enum MaterialAlignmentDirection { public class MaterialCollectionViewLayout : UICollectionViewLayout {
case None
case Vertical
case Horizontal
}
public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
/// Used to calculate the dimensions of the cells. /// Used to calculate the dimensions of the cells.
internal var offset: CGPoint = CGPointZero internal var offset: CGPoint = CGPointZero
/// The size of items.
public var itemSize: CGSize = CGSizeZero
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None { public var contentInsetPreset: MaterialEdgeInset = .None {
didSet { didSet {
...@@ -59,8 +56,8 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout { ...@@ -59,8 +56,8 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
/// Cell items. /// Cell items.
public private(set) var items: Array<MaterialDataSourceItem>? public private(set) var items: Array<MaterialDataSourceItem>?
/// Alignment direction. /// Scroll direction.
public var alignmentDirection: MaterialAlignmentDirection = .None public var scrollDirection: UICollectionViewScrollDirection = .Vertical
/// A preset wrapper around spacing. /// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None { public var spacingPreset: MaterialSpacing = .None {
...@@ -88,50 +85,32 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout { ...@@ -88,50 +85,32 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
} }
public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForItemAtIndexPath(indexPath)! let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
let item: MaterialDataSourceItem = items![indexPath.item] let item: MaterialDataSourceItem = items![indexPath.item]
switch alignmentDirection { if 0 < itemSize.width && 0 < itemSize.height {
case .Vertical: attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, itemSize.height - contentInset.top - contentInset.bottom)
} else if .Vertical == scrollDirection {
attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, nil == item.height ? collectionView!.bounds.height : item.height!) attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, nil == item.height ? collectionView!.bounds.height : item.height!)
case .Horizontal: } else {
attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, collectionView!.bounds.height - contentInset.top - contentInset.bottom) attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, collectionView!.bounds.height - contentInset.top - contentInset.bottom)
case .None:
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, itemSize.height - contentInset.top - contentInset.bottom)
}
return attributes
}
public override func layoutAttributesForSupplementaryViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForSupplementaryViewOfKind(elementKind, atIndexPath: indexPath)!
let item: MaterialDataSourceItem = items![indexPath.item]
switch alignmentDirection {
case .Vertical:
attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, 44)
case .Horizontal:
attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, 44)
case .None:
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, headerReferenceSize.height - contentInset.top - contentInset.bottom)
} }
return attributes return attributes
} }
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes: Array<UICollectionViewLayoutAttributes> = super.layoutAttributesForElementsInRect(rect)! var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>()
return attributes for (attribute, _) in layoutItems {
} if CGRectIntersectsRect(rect, attribute.frame) {
layoutAttributes.append(attribute)
public override func layoutAttributesForDecorationViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { }
let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForDecorationViewOfKind(elementKind, atIndexPath: indexPath)! }
return attributes return layoutAttributes
} }
public override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool { public override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return .Vertical == scrollDirection ? newBounds.width != collectionView?.bounds.width : newBounds.height != collectionView?.bounds.height return .Vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height
} }
public override func collectionViewContentSize() -> CGSize { public override func collectionViewContentSize() -> CGSize {
...@@ -157,10 +136,10 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout { ...@@ -157,10 +136,10 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
let item: MaterialDataSourceItem = items[i] let item: MaterialDataSourceItem = items[i]
indexPath = NSIndexPath(forItem: i, inSection: 0) indexPath = NSIndexPath(forItem: i, inSection: 0)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!)) layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
offset.x += spacing offset.x += spacing
offset.x += nil == item.width ? itemSize.width : item.width! offset.x += nil == item.width ? itemSize.width : item.width!
offset.y += spacing offset.y += spacing
offset.y += nil == item.height ? itemSize.height : item.height! offset.y += nil == item.height ? itemSize.height : item.height!
} }
...@@ -168,17 +147,16 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout { ...@@ -168,17 +147,16 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
offset.x += contentInset.right - spacing offset.x += contentInset.right - spacing
offset.y += contentInset.bottom - spacing offset.y += contentInset.bottom - spacing
switch alignmentDirection { if 0 < itemSize.width && 0 < itemSize.height {
case .Vertical: contentSize = CGSizeMake(offset.x, offset.y)
} else if .Vertical == scrollDirection {
contentSize = CGSizeMake(collectionView!.bounds.width, offset.y) contentSize = CGSizeMake(collectionView!.bounds.width, offset.y)
case .Horizontal: } else {
contentSize = CGSizeMake(offset.x, collectionView!.bounds.height) contentSize = CGSizeMake(offset.x, collectionView!.bounds.height)
case .None:
contentSize = CGSizeMake(offset.x, offset.y)
} }
} }
public override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint) -> CGPoint { public override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint) -> CGPoint {
return proposedContentOffset return proposedContentOffset
} }
} }
\ No newline at end of file
...@@ -111,9 +111,9 @@ public class SearchBar : BarView { ...@@ -111,9 +111,9 @@ public class SearchBar : BarView {
super.init(frame: frame) super.init(frame: frame)
} }
/// Basic initializer. /// Convenience initializer.
public override init() { public convenience init() {
super.init() self.init(frame: CGRectZero)
} }
/** /**
......
...@@ -74,9 +74,9 @@ public class Toolbar : BarView { ...@@ -74,9 +74,9 @@ public class Toolbar : BarView {
super.init(frame: frame) super.init(frame: frame)
} }
/// Basic initializer. /// Convenience initializer.
public override init() { public convenience init() {
super.init() self.init(frame: CGRectZero)
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment