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

Update to Swift 5.0 #42

Merged
merged 2 commits into from
Apr 10, 2019
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: swift
osx_image: xcode9
osx_image: xcode10.2
xcode_project: Example/CenteredCollectionView.xcworkspace
xcode_schema: CenteredCollectionView_Tests
notifications:
Expand Down
2 changes: 1 addition & 1 deletion CenteredCollectionView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Pod::Spec.new do |s|

# s.platform = :ios
s.ios.deployment_target = '9.0'
s.swift_version = '4.2'
s.swift_version = '5.0'

# When using multiple platforms
# s.ios.deployment_target = '5.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public extension UICollectionView {
/// - Parameters:
/// - frame: The frame rectangle for the collection view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This frame is passed to the superclass during initialization.
/// - centeredCollectionViewFlowLayout: The `CenteredCollectionViewFlowLayout` for the `UICollectionView` to be configured with.
public convenience init(frame: CGRect = .zero, centeredCollectionViewFlowLayout: CenteredCollectionViewFlowLayout) {
convenience init(frame: CGRect = .zero, centeredCollectionViewFlowLayout: CenteredCollectionViewFlowLayout) {
self.init(frame: frame, collectionViewLayout: centeredCollectionViewFlowLayout)
decelerationRate = UIScrollView.DecelerationRate.fast
}
Expand All @@ -31,7 +31,10 @@ open class CenteredCollectionViewFlowLayout: UICollectionViewFlowLayout {
return itemSize.width + minimumLineSpacing
case .vertical:
return itemSize.height + minimumLineSpacing
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: remove this extra newline

Suggested change

default:
return 0
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing here doesn't match the rest of the code. Would you mind making the stacking consistent with the rest of the file?

}

/// Calculates the current centered page.
Expand Down Expand Up @@ -70,6 +73,10 @@ open class CenteredCollectionViewFlowLayout: UICollectionViewFlowLayout {
let inset = (currentCollectionViewSize.height - itemSize.height) / 2
collectionView.contentInset = UIEdgeInsets(top: inset, left: 0, bottom: inset, right: 0)
collectionView.contentOffset = CGPoint(x: 0, y: -inset)

default:
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
collectionView.contentOffset = .zero
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing here doesn't match the rest of the code. Would you mind making the stacking consistent with the rest of the file?

}
lastCollectionViewSize = currentCollectionViewSize
lastScrollDirection = scrollDirection
Expand Down Expand Up @@ -111,6 +118,9 @@ open class CenteredCollectionViewFlowLayout: UICollectionViewFlowLayout {
newOffset += velocity.y > 0 ? pageHeight : -pageHeight
}
return CGPoint(x: proposedContentOffset.x, y: newOffset)

default:
return .zero
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing here doesn't match the rest of the code. Would you mind making the stacking consistent with the rest of the file?

}
}

Expand All @@ -133,6 +143,10 @@ open class CenteredCollectionViewFlowLayout: UICollectionViewFlowLayout {
let pageOffset = CGFloat(index) * pageWidth - collectionView.contentInset.top
proposedContentOffset = CGPoint(x: collectionView.contentOffset.x, y: pageOffset)
shouldAnimate = abs(collectionView.contentOffset.y - pageOffset) > 1 ? animated : false

default:
proposedContentOffset = .zero
shouldAnimate = false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing here doesn't match the rest of the code. Would you mind making the stacking consistent with the rest of the file?

}
collectionView.setContentOffset(proposedContentOffset, animated: shouldAnimate)
}
Expand All @@ -148,6 +162,8 @@ private extension CenteredCollectionViewFlowLayout {
origin = CGPoint(x: proposedContentOffset.x, y: collectionView.contentOffset.y)
case .vertical:
origin = CGPoint(x: collectionView.contentOffset.x, y: proposedContentOffset.y)
default:
origin = .zero
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing here doesn't match the rest of the code. Would you mind making the stacking consistent with the rest of the file?

}
return CGRect(origin: origin, size: size)
}
Expand All @@ -166,6 +182,8 @@ private extension CenteredCollectionViewFlowLayout {
proposedCenterOffset = proposedContentOffset.x + collectionView.bounds.size.width / 2
case .vertical:
proposedCenterOffset = proposedContentOffset.y + collectionView.bounds.size.height / 2
default:
proposedCenterOffset = .zero
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing here doesn't match the rest of the code. Would you mind making the stacking consistent with the rest of the file?

}

for attributes in layoutAttributes {
Expand Down
22 changes: 10 additions & 12 deletions Example/CenteredCollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,24 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 1010;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0920;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0920;
LastSwiftMigration = 1020;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
};
buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "CenteredCollectionView" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -482,6 +482,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -538,6 +539,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -599,8 +601,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -620,8 +621,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "io.github.benemdon.CenteredCollectionView-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -640,8 +640,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -656,8 +655,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Example/CenteredCollectionView/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

return true
Expand Down
4 changes: 2 additions & 2 deletions Example/CenteredCollectionView/ControlCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

protocol ControlCenterViewDelegate: class {
func stateChanged(scrollDirection: UICollectionViewScrollDirection)
func stateChanged(scrollDirection: UICollectionView.ScrollDirection)
func stateChanged(scrollToEdgeEnabled: Bool)
}

Expand Down Expand Up @@ -70,7 +70,7 @@ class ControlCenterView: UIView {
// MARK: - Actions

@objc func controlStateDidChange(sender: UISegmentedControl) {
guard let scrollDirection = UICollectionViewScrollDirection(rawValue: sender.selectedSegmentIndex) else { return }
guard let scrollDirection = UICollectionView.ScrollDirection(rawValue: sender.selectedSegmentIndex) else { return }
delegate?.stateChanged(scrollDirection: scrollDirection)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ProgrammaticViewController: UIViewController {
}

extension ProgrammaticViewController: ControlCenterViewDelegate {
func stateChanged(scrollDirection: UICollectionViewScrollDirection) {
func stateChanged(scrollDirection: UICollectionView.ScrollDirection) {
centeredCollectionViewFlowLayout.scrollDirection = scrollDirection
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class StoryboardViewController: UIViewController {
centeredCollectionViewFlowLayout = (collectionView.collectionViewLayout as! CenteredCollectionViewFlowLayout)

// Modify the collectionView's decelerationRate (REQURED)
collectionView.decelerationRate = UIScrollViewDecelerationRateFast
collectionView.decelerationRate = UIScrollView.DecelerationRate.fast

// Make the example pretty ✨
view.applyGradient()
Expand Down
15 changes: 10 additions & 5 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/BenEmdon/CenteredCollectionView.svg?branch=master)](https://travis-ci.org/BenEmdon/CenteredCollectionView)
[![Version](https://img.shields.io/cocoapods/v/CenteredCollectionView.svg?style=flat)](http://cocoapods.org/pods/CenteredCollectionView)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg?style=flat)](https://swift.org)
[![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat)](https://swift.org)
[![Platform](https://img.shields.io/badge/platforms-iOS%20%7C%20tvOS-orange.svg)](http://cocoapods.org/pods/CenteredCollectionView)

`CenteredCollectionView` is a lightweight drop in place `UICollectionViewFlowLayout` that _pages_ and keeps its cells centered, resulting in the _"carousel effect"_ 🎡
Expand Down