Skip to content

Commit d44f8fa

Browse files
committed
update to version 2.1.0
1 parent 39160b3 commit d44f8fa

12 files changed

Lines changed: 189 additions & 17 deletions

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
osx_image: xcode7.2.1
2+
3+
language: objective-c
4+
5+
script: ./test.sh
6+
7+
after_success:
8+
- bash <(curl -s https://codecov.io/bash)

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# YBSlantedCollectionViewLayout CHANGELOG
22

3+
## 2.1.0
4+
5+
* Add tests
6+
* Remove the `applyMaskToCellView (cellView : UICollectionViewCell, forIndexPath: NSIndexPath)` method
7+
38
## 2.0.0
49

510
* Carthage support

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
[![License](https://img.shields.io/cocoapods/l/YBSlantedCollectionViewLayout.svg?style=flat)](http://cocoapods.org/pods/YBSlantedCollectionViewLayout)
55
[![Platform](https://img.shields.io/cocoapods/p/YBSlantedCollectionViewLayout.svg?style=flat)](http://cocoapods.org/pods/YBSlantedCollectionViewLayout)
66
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
7+
[![Build Status](https://travis-ci.org/yacir/YBSlantedCollectionViewLayout.svg?branch=master)](https://travis-ci.org/yacir/YBSlantedCollectionViewLayout)
8+
[![codecov.io](https://codecov.io/github/yacir/YBSlantedCollectionViewLayout/coverage.svg?branch=master)](https://codecov.io/github/yacir/YBSlantedCollectionViewLayout?branch=master)
79

810
## Overview
911
YBSlantedCollectionViewLayout is a subclass of UICollectionViewLayout allowing the display of slanted content on UICollectionView.
1012

1113
## [Live Demo] (https://appetize.io/app/nd8vgwg0rkke19nmw3wzkapr5g)
1214

1315
<p align="center" >
16+
1417
<img src="https://cloud.githubusercontent.com/assets/2587473/13427516/d9af399e-dfb4-11e5-8109-ae997dc7c340.gif" alt="YBSlantedCollectionViewLayout" title="YBSlantedCollectionViewLayout">
18+
1519
</p>
1620

1721
## Usage
@@ -61,7 +65,7 @@ github 'yacir/YBSlantedCollectionViewLayout'
6165
## Roadmap
6266
- [x] Improve the attribution of the clic
6367
- [x] Carthage support
64-
- [] Tests
68+
- [x] Tests
6569

6670
## Author
6771

Source/YBSlantedCollectionViewCell.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ import UIKit
3030
*/
3131
public class YBSlantedCollectionViewCell: UICollectionViewCell {
3232

33+
/// :nodoc:
3334
private var slantedLayerMask: CAShapeLayer?
3435

36+
/// :nodoc:
3537
override public func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
3638

3739
if (self.slantedLayerMask != nil) {
@@ -44,6 +46,7 @@ public class YBSlantedCollectionViewCell: UICollectionViewCell {
4446
return (super.pointInside(point, withEvent: event))
4547
}
4648

49+
/// :nodoc:
4750
override public func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) {
4851
let attributes = layoutAttributes as! YBSlantedCollectionViewLayoutAttributes
4952
super.applyLayoutAttributes(attributes)

Source/YBSlantedCollectionViewLayout.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ public class YBSlantedCollectionViewLayout: UICollectionViewLayout {
125125
internal var hasVerticalDirection: Bool {
126126
return scrollDirection == UICollectionViewScrollDirection.Vertical
127127
}
128-
129-
/// :nodoc:
130-
@available(*, deprecated, message="Use YBSlantedCollectionViewCell")
131-
public func applyMaskToCellView (cellView : UICollectionViewCell, forIndexPath: NSIndexPath) {
132-
cellView.layer.mask = self.maskForItemAtIndexPath(forIndexPath)
133-
}
134128

135129
/// :nodoc:
136130
private func maskForItemAtIndexPath(indexPath: NSIndexPath) -> CAShapeLayer {

Source/YBSlantedCollectionViewLayoutAttributes.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@
2424

2525
import UIKit
2626

27+
/// :nodoc:
2728
public class YBSlantedCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes {
2829

30+
/// :nodoc:
2931
public var slantedLayerMask :CAShapeLayer?
3032

33+
/// :nodoc:
3134
override public func copyWithZone(zone: NSZone) -> AnyObject {
3235

3336
let attributesCopy = super.copyWithZone(zone) as! YBSlantedCollectionViewLayoutAttributes
3437
attributesCopy.slantedLayerMask = self.slantedLayerMask
3538
return attributesCopy
3639
}
3740

41+
/// :nodoc:
3842
override public func isEqual(object: AnyObject?) -> Bool {
3943

4044
if let o = object as? YBSlantedCollectionViewLayoutAttributes {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
//
3+
// CollectionViewController.swift
4+
// YBSlantedCollectionViewLayout
5+
//
6+
// Created by Yassir Barchi on 23/03/2016.
7+
// Copyright © 2016 Yassir Barchi. All rights reserved.
8+
//
9+
10+
import UIKit
11+
12+
@testable import YBSlantedCollectionViewLayout
13+
14+
private let reuseIdentifier = "Cell"
15+
16+
class CollectionViewController: UICollectionViewController {
17+
18+
var items = [Int]()
19+
20+
override func viewDidLoad() {
21+
super.viewDidLoad()
22+
23+
self.collectionView!.registerClass(YBSlantedCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
24+
}
25+
26+
// MARK: UICollectionViewDataSource
27+
28+
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
29+
return 1
30+
}
31+
32+
33+
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
34+
return items.count
35+
}
36+
37+
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
38+
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
39+
40+
// Configure the cell
41+
42+
return cell
43+
}
44+
45+
46+
}
47+

Tests/YBSlantedCollectionViewLayoutTests.swift

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,115 @@ import XCTest
1111

1212
class YBSlantedCollectionViewLayoutTests: XCTestCase {
1313

14+
var verticalSlantedViewLayout: YBSlantedCollectionViewLayout!
15+
var collectionViewController: CollectionViewController!
16+
17+
var horizontalSlantedViewLayout: YBSlantedCollectionViewLayout!
18+
var horizontalCollectionViewController: CollectionViewController!
19+
1420
override func setUp() {
1521
super.setUp()
1622
// Put setup code here. This method is called before the invocation of each test method in the class.
23+
verticalSlantedViewLayout = YBSlantedCollectionViewLayout()
24+
collectionViewController = CollectionViewController(collectionViewLayout: verticalSlantedViewLayout)
25+
collectionViewController.view.frame = CGRect(x: 0, y: 0, width: 600, height: 600)
26+
27+
horizontalSlantedViewLayout = YBSlantedCollectionViewLayout()
28+
horizontalSlantedViewLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
29+
horizontalSlantedViewLayout.lineSpacing = 3
30+
horizontalSlantedViewLayout.itemSizeOptions = YBSlantedCollectionViewLayoutSizeOptions(VerticalSize: 100, HorizontalSize: 210)
31+
horizontalSlantedViewLayout.reverseSlantingAngle = true
32+
horizontalCollectionViewController = CollectionViewController(collectionViewLayout: horizontalSlantedViewLayout)
33+
horizontalCollectionViewController.view.frame = CGRect(x: 0, y: 0, width: 600, height: 600)
1734
}
1835

1936
override func tearDown() {
2037
// Put teardown code here. This method is called after the invocation of each test method in the class.
2138
super.tearDown()
2239
}
2340

24-
func testExample() {
25-
// This is an example of a functional test case.
26-
// Use XCTAssert and related functions to verify your tests produce the correct results.
41+
func testSlantedViewLayoutHasDefaultValues() {
42+
XCTAssertEqual(verticalSlantedViewLayout.slantingDelta, 50)
43+
XCTAssertEqual(verticalSlantedViewLayout.reverseSlantingAngle, false)
44+
XCTAssertEqual(verticalSlantedViewLayout.firstCellSlantingEnabled, true)
45+
XCTAssertEqual(verticalSlantedViewLayout.lastCellSlantingEnabled, true)
46+
XCTAssertEqual(verticalSlantedViewLayout.lineSpacing, 10)
47+
XCTAssertEqual(verticalSlantedViewLayout.scrollDirection, UICollectionViewScrollDirection.Vertical)
48+
XCTAssertEqual(verticalSlantedViewLayout.itemSizeOptions.VerticalSize, 220)
49+
XCTAssertEqual(verticalSlantedViewLayout.itemSizeOptions.HorizontalSize, 290)
50+
}
51+
52+
func testLayoutContentViewSizeUsesController() {
53+
collectionViewController.items = [0, 1, 2, 3, 5, 6, 7, 8, 9]
54+
collectionViewController.view.layoutIfNeeded()
55+
56+
let verticalSlantedViewLayoutSize = self.verticalSlantedViewLayout.collectionViewContentSize()
57+
let collectionViewControllerSize = self.collectionViewController.view.frame.size
58+
59+
let size = verticalSlantedViewLayout.itemSizeOptions.VerticalSize
60+
let lineSpicing = verticalSlantedViewLayout.lineSpacing
61+
let slantingDelta = CGFloat(verticalSlantedViewLayout.slantingDelta)
62+
63+
let contentSize = CGFloat(collectionViewController.items.count) * (size - slantingDelta + lineSpicing ) + slantingDelta - lineSpicing
64+
XCTAssertEqual(verticalSlantedViewLayoutSize.width, collectionViewControllerSize.width)
65+
XCTAssertEqual(verticalSlantedViewLayoutSize.height, contentSize)
66+
}
67+
68+
func testHorizontalLayoutContentViewSizeUsesController() {
69+
horizontalCollectionViewController.items = [0, 1, 2, 3, 5, 6, 7, 8, 9]
70+
horizontalCollectionViewController.view.layoutIfNeeded()
71+
72+
let verticalSlantedViewLayoutSize = horizontalSlantedViewLayout.collectionViewContentSize()
73+
let collectionViewControllerSize = horizontalCollectionViewController.view.frame.size
74+
75+
let size = horizontalSlantedViewLayout.itemSizeOptions.HorizontalSize
76+
let lineSpicing = horizontalSlantedViewLayout.lineSpacing
77+
let slantingDelta = CGFloat(horizontalSlantedViewLayout.slantingDelta)
78+
79+
let contentSize = CGFloat(horizontalCollectionViewController.items.count) * (size - slantingDelta + lineSpicing ) + slantingDelta - lineSpicing
80+
XCTAssertEqual(verticalSlantedViewLayoutSize.width, contentSize)
81+
XCTAssertEqual(verticalSlantedViewLayoutSize.height, collectionViewControllerSize.height)
82+
}
83+
84+
85+
func testLayoutHasSmoothScrolling() {
86+
let proposedOffset = verticalSlantedViewLayout.targetContentOffsetForProposedContentOffset(CGPoint(), withScrollingVelocity: CGPoint())
87+
88+
XCTAssertEqual(proposedOffset.x, 0)
89+
XCTAssertEqual(proposedOffset.y, 0)
90+
}
91+
92+
func testLayoutHasCachedLayoutAttributes() {
93+
collectionViewController.items = [0]
94+
95+
collectionViewController.view.layoutIfNeeded()
96+
97+
XCTAssertEqual(verticalSlantedViewLayout.cached.count, 1);
98+
}
99+
100+
func testLayoutAttributeIsCached() {
101+
collectionViewController.items = [0]
102+
103+
collectionViewController.view.layoutIfNeeded()
104+
105+
let attributes = verticalSlantedViewLayout.layoutAttributesForElementsInRect(CGRect())!
106+
107+
XCTAssertEqual(verticalSlantedViewLayout.cached, attributes)
108+
}
109+
110+
func testLayoutHasLayoutAttributesAtIndexPath() {
111+
collectionViewController.items = [0, 1, 2]
112+
113+
collectionViewController.view.layoutIfNeeded()
114+
115+
let indexPath = NSIndexPath(forItem: 0, inSection: 0)
116+
let attribute = verticalSlantedViewLayout.layoutAttributesForItemAtIndexPath(indexPath)
117+
118+
XCTAssertEqual(verticalSlantedViewLayout.cached[0], attribute)
27119
}
28120

29-
func testPerformanceExample() {
30-
// This is an example of a performance test case.
31-
self.measureBlock {
32-
// Put the code you want to measure the time of here.
33-
}
121+
func testLayoutShouldInvalidateLayoutForBoundsChange() {
122+
XCTAssertTrue(verticalSlantedViewLayout.shouldInvalidateLayoutForBoundsChange(CGRect()))
34123
}
35124

36125
}

YBSlantedCollectionViewLayout.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "YBSlantedCollectionViewLayout"
3-
s.version = "2.0.0"
3+
s.version = "2.1.0"
44
s.summary = "UICollectionViewLayout allowing the display of slanted content on UICollectionView"
55

66
s.description = <<-DESC

YBSlantedCollectionViewLayout.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
FB132C641C910F5900728981 /* YBSlantedCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB132C611C910F5900728981 /* YBSlantedCollectionViewCell.swift */; };
1414
FB132C651C910F5900728981 /* YBSlantedCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB132C621C910F5900728981 /* YBSlantedCollectionViewLayout.swift */; };
1515
FB132C661C910F5900728981 /* YBSlantedCollectionViewLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB132C631C910F5900728981 /* YBSlantedCollectionViewLayoutAttributes.swift */; };
16+
FB40E22C1CA3530400B37E7C /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB40E22A1CA352FD00B37E7C /* CollectionViewController.swift */; };
1617
/* End PBXBuildFile section */
1718

1819
/* Begin PBXContainerItemProxy section */
@@ -35,6 +36,7 @@
3536
FB132C611C910F5900728981 /* YBSlantedCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YBSlantedCollectionViewCell.swift; sourceTree = "<group>"; };
3637
FB132C621C910F5900728981 /* YBSlantedCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YBSlantedCollectionViewLayout.swift; sourceTree = "<group>"; };
3738
FB132C631C910F5900728981 /* YBSlantedCollectionViewLayoutAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YBSlantedCollectionViewLayoutAttributes.swift; sourceTree = "<group>"; };
39+
FB40E22A1CA352FD00B37E7C /* CollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewController.swift; sourceTree = "<group>"; };
3840
/* End PBXFileReference section */
3941

4042
/* Begin PBXFrameworksBuildPhase section */
@@ -89,6 +91,7 @@
8991
isa = PBXGroup;
9092
children = (
9193
FB132C591C910C0300728981 /* YBSlantedCollectionViewLayoutTests.swift */,
94+
FB40E22A1CA352FD00B37E7C /* CollectionViewController.swift */,
9295
FB132C691C910F8200728981 /* Supporting Files */,
9396
);
9497
path = Tests;
@@ -229,6 +232,7 @@
229232
isa = PBXSourcesBuildPhase;
230233
buildActionMask = 2147483647;
231234
files = (
235+
FB40E22C1CA3530400B37E7C /* CollectionViewController.swift in Sources */,
232236
FB132C5F1C910E4300728981 /* YBSlantedCollectionViewLayoutTests.swift in Sources */,
233237
);
234238
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)