Skip to content

Commit

Permalink
update to version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yacir committed Mar 24, 2016
1 parent 39160b3 commit d44f8fa
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 17 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
osx_image: xcode7.2.1

language: objective-c

script: ./test.sh

after_success:
- bash <(curl -s https://codecov.io/bash)
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# YBSlantedCollectionViewLayout CHANGELOG

## 2.1.0

* Add tests
* Remove the `applyMaskToCellView (cellView : UICollectionViewCell, forIndexPath: NSIndexPath)` method

## 2.0.0

* Carthage support
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
[![License](https://img.shields.io/cocoapods/l/YBSlantedCollectionViewLayout.svg?style=flat)](http://cocoapods.org/pods/YBSlantedCollectionViewLayout)
[![Platform](https://img.shields.io/cocoapods/p/YBSlantedCollectionViewLayout.svg?style=flat)](http://cocoapods.org/pods/YBSlantedCollectionViewLayout)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Build Status](https://travis-ci.org/yacir/YBSlantedCollectionViewLayout.svg?branch=master)](https://travis-ci.org/yacir/YBSlantedCollectionViewLayout)
[![codecov.io](https://codecov.io/github/yacir/YBSlantedCollectionViewLayout/coverage.svg?branch=master)](https://codecov.io/github/yacir/YBSlantedCollectionViewLayout?branch=master)

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

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

<p align="center" >

<img src="https://cloud.githubusercontent.com/assets/2587473/13427516/d9af399e-dfb4-11e5-8109-ae997dc7c340.gif" alt="YBSlantedCollectionViewLayout" title="YBSlantedCollectionViewLayout">

</p>

## Usage
Expand Down Expand Up @@ -61,7 +65,7 @@ github 'yacir/YBSlantedCollectionViewLayout'
## Roadmap
- [x] Improve the attribution of the clic
- [x] Carthage support
- [] Tests
- [x] Tests

## Author

Expand Down
3 changes: 3 additions & 0 deletions Source/YBSlantedCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import UIKit
*/
public class YBSlantedCollectionViewCell: UICollectionViewCell {

/// :nodoc:
private var slantedLayerMask: CAShapeLayer?

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

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

/// :nodoc:
override public func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) {
let attributes = layoutAttributes as! YBSlantedCollectionViewLayoutAttributes
super.applyLayoutAttributes(attributes)
Expand Down
6 changes: 0 additions & 6 deletions Source/YBSlantedCollectionViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ public class YBSlantedCollectionViewLayout: UICollectionViewLayout {
internal var hasVerticalDirection: Bool {
return scrollDirection == UICollectionViewScrollDirection.Vertical
}

/// :nodoc:
@available(*, deprecated, message="Use YBSlantedCollectionViewCell")
public func applyMaskToCellView (cellView : UICollectionViewCell, forIndexPath: NSIndexPath) {
cellView.layer.mask = self.maskForItemAtIndexPath(forIndexPath)
}

/// :nodoc:
private func maskForItemAtIndexPath(indexPath: NSIndexPath) -> CAShapeLayer {
Expand Down
4 changes: 4 additions & 0 deletions Source/YBSlantedCollectionViewLayoutAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@

import UIKit

/// :nodoc:
public class YBSlantedCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes {

/// :nodoc:
public var slantedLayerMask :CAShapeLayer?

/// :nodoc:
override public func copyWithZone(zone: NSZone) -> AnyObject {

let attributesCopy = super.copyWithZone(zone) as! YBSlantedCollectionViewLayoutAttributes
attributesCopy.slantedLayerMask = self.slantedLayerMask
return attributesCopy
}

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

if let o = object as? YBSlantedCollectionViewLayoutAttributes {
Expand Down
47 changes: 47 additions & 0 deletions Tests/CollectionViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

//
// CollectionViewController.swift
// YBSlantedCollectionViewLayout
//
// Created by Yassir Barchi on 23/03/2016.
// Copyright © 2016 Yassir Barchi. All rights reserved.
//

import UIKit

@testable import YBSlantedCollectionViewLayout

private let reuseIdentifier = "Cell"

class CollectionViewController: UICollectionViewController {

var items = [Int]()

override func viewDidLoad() {
super.viewDidLoad()

self.collectionView!.registerClass(YBSlantedCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}

// MARK: UICollectionViewDataSource

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)

// Configure the cell

return cell
}


}

105 changes: 97 additions & 8 deletions Tests/YBSlantedCollectionViewLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,115 @@ import XCTest

class YBSlantedCollectionViewLayoutTests: XCTestCase {

var verticalSlantedViewLayout: YBSlantedCollectionViewLayout!
var collectionViewController: CollectionViewController!

var horizontalSlantedViewLayout: YBSlantedCollectionViewLayout!
var horizontalCollectionViewController: CollectionViewController!

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
verticalSlantedViewLayout = YBSlantedCollectionViewLayout()
collectionViewController = CollectionViewController(collectionViewLayout: verticalSlantedViewLayout)
collectionViewController.view.frame = CGRect(x: 0, y: 0, width: 600, height: 600)

horizontalSlantedViewLayout = YBSlantedCollectionViewLayout()
horizontalSlantedViewLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
horizontalSlantedViewLayout.lineSpacing = 3
horizontalSlantedViewLayout.itemSizeOptions = YBSlantedCollectionViewLayoutSizeOptions(VerticalSize: 100, HorizontalSize: 210)
horizontalSlantedViewLayout.reverseSlantingAngle = true
horizontalCollectionViewController = CollectionViewController(collectionViewLayout: horizontalSlantedViewLayout)
horizontalCollectionViewController.view.frame = CGRect(x: 0, y: 0, width: 600, height: 600)
}

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

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
func testSlantedViewLayoutHasDefaultValues() {
XCTAssertEqual(verticalSlantedViewLayout.slantingDelta, 50)
XCTAssertEqual(verticalSlantedViewLayout.reverseSlantingAngle, false)
XCTAssertEqual(verticalSlantedViewLayout.firstCellSlantingEnabled, true)
XCTAssertEqual(verticalSlantedViewLayout.lastCellSlantingEnabled, true)
XCTAssertEqual(verticalSlantedViewLayout.lineSpacing, 10)
XCTAssertEqual(verticalSlantedViewLayout.scrollDirection, UICollectionViewScrollDirection.Vertical)
XCTAssertEqual(verticalSlantedViewLayout.itemSizeOptions.VerticalSize, 220)
XCTAssertEqual(verticalSlantedViewLayout.itemSizeOptions.HorizontalSize, 290)
}

func testLayoutContentViewSizeUsesController() {
collectionViewController.items = [0, 1, 2, 3, 5, 6, 7, 8, 9]
collectionViewController.view.layoutIfNeeded()

let verticalSlantedViewLayoutSize = self.verticalSlantedViewLayout.collectionViewContentSize()
let collectionViewControllerSize = self.collectionViewController.view.frame.size

let size = verticalSlantedViewLayout.itemSizeOptions.VerticalSize
let lineSpicing = verticalSlantedViewLayout.lineSpacing
let slantingDelta = CGFloat(verticalSlantedViewLayout.slantingDelta)

let contentSize = CGFloat(collectionViewController.items.count) * (size - slantingDelta + lineSpicing ) + slantingDelta - lineSpicing
XCTAssertEqual(verticalSlantedViewLayoutSize.width, collectionViewControllerSize.width)
XCTAssertEqual(verticalSlantedViewLayoutSize.height, contentSize)
}

func testHorizontalLayoutContentViewSizeUsesController() {
horizontalCollectionViewController.items = [0, 1, 2, 3, 5, 6, 7, 8, 9]
horizontalCollectionViewController.view.layoutIfNeeded()

let verticalSlantedViewLayoutSize = horizontalSlantedViewLayout.collectionViewContentSize()
let collectionViewControllerSize = horizontalCollectionViewController.view.frame.size

let size = horizontalSlantedViewLayout.itemSizeOptions.HorizontalSize
let lineSpicing = horizontalSlantedViewLayout.lineSpacing
let slantingDelta = CGFloat(horizontalSlantedViewLayout.slantingDelta)

let contentSize = CGFloat(horizontalCollectionViewController.items.count) * (size - slantingDelta + lineSpicing ) + slantingDelta - lineSpicing
XCTAssertEqual(verticalSlantedViewLayoutSize.width, contentSize)
XCTAssertEqual(verticalSlantedViewLayoutSize.height, collectionViewControllerSize.height)
}


func testLayoutHasSmoothScrolling() {
let proposedOffset = verticalSlantedViewLayout.targetContentOffsetForProposedContentOffset(CGPoint(), withScrollingVelocity: CGPoint())

XCTAssertEqual(proposedOffset.x, 0)
XCTAssertEqual(proposedOffset.y, 0)
}

func testLayoutHasCachedLayoutAttributes() {
collectionViewController.items = [0]

collectionViewController.view.layoutIfNeeded()

XCTAssertEqual(verticalSlantedViewLayout.cached.count, 1);
}

func testLayoutAttributeIsCached() {
collectionViewController.items = [0]

collectionViewController.view.layoutIfNeeded()

let attributes = verticalSlantedViewLayout.layoutAttributesForElementsInRect(CGRect())!

XCTAssertEqual(verticalSlantedViewLayout.cached, attributes)
}

func testLayoutHasLayoutAttributesAtIndexPath() {
collectionViewController.items = [0, 1, 2]

collectionViewController.view.layoutIfNeeded()

let indexPath = NSIndexPath(forItem: 0, inSection: 0)
let attribute = verticalSlantedViewLayout.layoutAttributesForItemAtIndexPath(indexPath)

XCTAssertEqual(verticalSlantedViewLayout.cached[0], attribute)
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
// Put the code you want to measure the time of here.
}
func testLayoutShouldInvalidateLayoutForBoundsChange() {
XCTAssertTrue(verticalSlantedViewLayout.shouldInvalidateLayoutForBoundsChange(CGRect()))
}

}
2 changes: 1 addition & 1 deletion YBSlantedCollectionViewLayout.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "YBSlantedCollectionViewLayout"
s.version = "2.0.0"
s.version = "2.1.0"
s.summary = "UICollectionViewLayout allowing the display of slanted content on UICollectionView"

s.description = <<-DESC
Expand Down
4 changes: 4 additions & 0 deletions YBSlantedCollectionViewLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
FB132C641C910F5900728981 /* YBSlantedCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB132C611C910F5900728981 /* YBSlantedCollectionViewCell.swift */; };
FB132C651C910F5900728981 /* YBSlantedCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB132C621C910F5900728981 /* YBSlantedCollectionViewLayout.swift */; };
FB132C661C910F5900728981 /* YBSlantedCollectionViewLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB132C631C910F5900728981 /* YBSlantedCollectionViewLayoutAttributes.swift */; };
FB40E22C1CA3530400B37E7C /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB40E22A1CA352FD00B37E7C /* CollectionViewController.swift */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -89,6 +91,7 @@
isa = PBXGroup;
children = (
FB132C591C910C0300728981 /* YBSlantedCollectionViewLayoutTests.swift */,
FB40E22A1CA352FD00B37E7C /* CollectionViewController.swift */,
FB132C691C910F8200728981 /* Supporting Files */,
);
path = Tests;
Expand Down Expand Up @@ -229,6 +232,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FB40E22C1CA3530400B37E7C /* CollectionViewController.swift in Sources */,
FB132C5F1C910E4300728981 /* YBSlantedCollectionViewLayoutTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
13 changes: 13 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /bin/bash
TEST_CMD="xcodebuild -scheme YBSlantedCollectionViewLayout -workspace YBSlantedCollectionViewLayout.xcworkspace -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6S,OS=9.1' build test"

which -s xcpretty
XCPRETTY_INSTALLED=$?

if [[ $TRAVIS || $XCPRETTY_INSTALLED == 0 ]]; then
eval "${TEST_CMD} | xcpretty"
else
eval "$TEST_CMD"
fi

pod lib lint --quick

0 comments on commit d44f8fa

Please sign in to comment.