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

Updated to Xcode 11.3 and Swift 5 #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 Demo/TabPageViewControllerDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/TabCollectionCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

class TabCollectionCell: UICollectionViewCell {

var tabItemButtonPressedBlock: ((Void) -> Void)?
var tabItemButtonPressedBlock: (() -> Void)?
var option: TabPageOption = TabPageOption() {
didSet {
currentBarViewHeightConstraint.constant = option.currentBarHeight
Expand Down Expand Up @@ -47,7 +47,7 @@ class TabCollectionCell: UICollectionViewCell {
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
if item.characters.count == 0 {
if item.count == 0 {
return CGSize.zero
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/TabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class TabPageViewController: UIPageViewController {
guard let viewController = viewControllers?.first else {
return nil
}
return tabItems.map{ $0.viewController }.index(of: viewController)
return tabItems.map{ $0.viewController }.firstIndex(of: viewController)
}
fileprivate var beforeIndex: Int = 0
fileprivate var tabItemsCount: Int {
Expand Down Expand Up @@ -80,7 +80,7 @@ open class TabPageViewController: UIPageViewController {

public extension TabPageViewController {

public func displayControllerWithIndex(_ index: Int, direction: UIPageViewControllerNavigationDirection, animated: Bool) {
func displayControllerWithIndex(_ index: Int, direction: UIPageViewController.NavigationDirection, animated: Bool) {

beforeIndex = index
shouldScrollCurrentBar = false
Expand Down Expand Up @@ -120,7 +120,7 @@ extension TabPageViewController {

fileprivate func setupScrollView() {
// Disable PageViewController's ScrollView bounce
let scrollView = view.subviews.flatMap { $0 as? UIScrollView }.first
let scrollView = view.subviews.compactMap { $0 as? UIScrollView }.first
scrollView?.scrollsToTop = false
scrollView?.delegate = self
scrollView?.backgroundColor = option.pageBackgoundColor
Expand Down Expand Up @@ -168,7 +168,7 @@ extension TabPageViewController {
multiplier: 1.0,
constant: 0.0)

let right = NSLayoutConstraint(item: view,
let right = NSLayoutConstraint(item: view as Any,
attribute: .trailing,
relatedBy: .equal,
toItem: tabView,
Expand All @@ -181,7 +181,7 @@ extension TabPageViewController {
tabView.pageTabItems = tabItems.map({ $0.title})
tabView.updateCurrentIndex(beforeIndex, shouldScroll: true)

tabView.pageItemPressedBlock = { [weak self] (index: Int, direction: UIPageViewControllerNavigationDirection) in
tabView.pageItemPressedBlock = { [weak self] (index: Int, direction: UIPageViewController.NavigationDirection) in
self?.displayControllerWithIndex(index, direction: direction, animated: true)
}

Expand Down Expand Up @@ -212,7 +212,7 @@ extension TabPageViewController {
multiplier: 1.0,
constant: 0.0)

let right = NSLayoutConstraint(item: view,
let right = NSLayoutConstraint(item: view as Any,
attribute: .trailing,
relatedBy: .equal,
toItem: statusView,
Expand Down Expand Up @@ -270,7 +270,7 @@ extension TabPageViewController {

if option.hidesTopViewOnSwipeType != .none {
tabBarTopConstraint.constant = 0.0
UIView.animate(withDuration: TimeInterval(UINavigationControllerHideShowBarDuration)) {
UIView.animate(withDuration: TimeInterval(UINavigationController.hideShowBarDuration)) {
self.view.layoutIfNeeded()
}
}
Expand All @@ -283,7 +283,7 @@ extension TabPageViewController {
guard let tabBarTopConstraint = tabBarTopConstraint else { return }

tabBarTopConstraint.constant = hidden ? -(20.0 + option.tabHeight) : 0.0
UIView.animate(withDuration: TimeInterval(UINavigationControllerHideShowBarDuration)) {
UIView.animate(withDuration: TimeInterval(UINavigationController.hideShowBarDuration)) {
self.view.layoutIfNeeded()
}
}
Expand All @@ -296,7 +296,7 @@ extension TabPageViewController: UIPageViewControllerDataSource {

fileprivate func nextViewController(_ viewController: UIViewController, isAfter: Bool) -> UIViewController? {

guard var index = tabItems.map({$0.viewController}).index(of: viewController) else {
guard var index = tabItems.map({$0.viewController}).firstIndex(of: viewController) else {
return nil
}

Expand Down
34 changes: 17 additions & 17 deletions Sources/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

internal class TabView: UIView {

var pageItemPressedBlock: ((_ index: Int, _ direction: UIPageViewControllerNavigationDirection) -> Void)?
var pageItemPressedBlock: ((_ index: Int, _ direction: UIPageViewController.NavigationDirection) -> Void)?
var pageTabItems: [String] = [] {
didSet {
pageTabItemsCount = pageTabItems.count
Expand Down Expand Up @@ -47,15 +47,15 @@ internal class TabView: UIView {
addSubview(contentView)
contentView.backgroundColor = option.tabBackgroundColor.withAlphaComponent(option.tabBarAlpha)

let top = NSLayoutConstraint(item: contentView,
let top = NSLayoutConstraint(item: contentView as Any,
attribute: .top,
relatedBy: .equal,
toItem: self,
attribute: .top,
multiplier: 1.0,
constant: 0.0)

let left = NSLayoutConstraint(item: contentView,
let left = NSLayoutConstraint(item: contentView as Any,
attribute: .leading,
relatedBy: .equal,
toItem: self,
Expand Down Expand Up @@ -85,7 +85,7 @@ internal class TabView: UIView {
let bundle = Bundle(for: TabView.self)
let nib = UINib(nibName: TabCollectionCell.cellIdentifier(), bundle: bundle)
collectionView.register(nib, forCellWithReuseIdentifier: TabCollectionCell.cellIdentifier())
cellForSize = nib.instantiate(withOwner: nil, options: nil).first as! TabCollectionCell
cellForSize = (nib.instantiate(withOwner: nil, options: nil).first as! TabCollectionCell)

collectionView.scrollsToTop = false

Expand All @@ -95,15 +95,15 @@ internal class TabView: UIView {
currentBarView.removeFromSuperview()
collectionView.addSubview(currentBarView)
currentBarView.translatesAutoresizingMaskIntoConstraints = false
let top = NSLayoutConstraint(item: currentBarView,
let top = NSLayoutConstraint(item: currentBarView as Any,
attribute: .top,
relatedBy: .equal,
toItem: collectionView,
attribute: .top,
multiplier: 1.0,
constant: option.tabHeight - currentBarViewHeightConstraint.constant)

let left = NSLayoutConstraint(item: currentBarView,
let left = NSLayoutConstraint(item: currentBarView as Any,
attribute: .leading,
relatedBy: .equal,
toItem: collectionView,
Expand Down Expand Up @@ -161,15 +161,15 @@ extension TabView {
let distance = (currentCell.frame.width / 2.0) + (nextCell.frame.width / 2.0)
let scrollRate = contentOffsetX / frame.width

if fabs(scrollRate) > 0.6 {
if abs(scrollRate) > 0.6 {
nextCell.highlightTitle()
currentCell.unHighlightTitle()
} else {
nextCell.unHighlightTitle()
currentCell.highlightTitle()
}

let width = fabs(scrollRate) * (nextCell.frame.width - currentCell.frame.width)
let width = abs(scrollRate) * (nextCell.frame.width - currentCell.frame.width)
if isInfinity {
let scroll = scrollRate * distance
collectionView.contentOffset.x = collectionViewContentOffsetX + scroll
Expand Down Expand Up @@ -277,7 +277,7 @@ extension TabView {
fileprivate func deselectVisibleCells() {
collectionView
.visibleCells
.flatMap { $0 as? TabCollectionCell }
.compactMap { $0 as? TabCollectionCell }
.forEach { $0.isCurrent = false }
}
}
Expand All @@ -302,10 +302,10 @@ extension TabView: UICollectionViewDataSource {
cell.item = pageTabItems[fixedIndex]
cell.option = option
cell.isCurrent = fixedIndex == (currentIndex % pageTabItemsCount)
cell.tabItemButtonPressedBlock = { [weak self, weak cell] in
var direction: UIPageViewControllerNavigationDirection = .forward
if let pageTabItemsCount = self?.pageTabItemsCount, let currentIndex = self?.currentIndex {
if self?.isInfinity == true {
cell.tabItemButtonPressedBlock = { [self, cell] in
var direction: UIPageViewController.NavigationDirection = .forward
if let pageTabItemsCount = self.pageTabItemsCount as Int?, let currentIndex = self.currentIndex as Int? {
if self.isInfinity == true {
if (indexPath.item < pageTabItemsCount) || (indexPath.item < currentIndex) {
direction = .reverse
}
Expand All @@ -315,13 +315,13 @@ extension TabView: UICollectionViewDataSource {
}
}
}
self?.pageItemPressedBlock?(fixedIndex, direction)
self.pageItemPressedBlock?(fixedIndex, direction)

if cell?.isCurrent == false {
if cell.isCurrent == false {
// Not accept touch events to scroll the animation is finished
self?.updateCollectionViewUserInteractionEnabled(false)
self.updateCollectionViewUserInteractionEnabled(false)
}
self?.updateCurrentIndexForTap(indexPath.item)
self.updateCurrentIndexForTap(indexPath.item)
}
}

Expand Down
7 changes: 5 additions & 2 deletions TabPageViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -428,7 +429,7 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -474,7 +475,7 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -498,6 +499,7 @@
PRODUCT_BUNDLE_IDENTIFIER = TabPageViewController;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_VERSION = 5.0;
TARGET_NAME = TabPageViewController;
};
name = Debug;
Expand All @@ -522,6 +524,7 @@
PRODUCT_BUNDLE_IDENTIFIER = TabPageViewController;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_VERSION = 5.0;
TARGET_NAME = TabPageViewController;
};
name = Release;
Expand Down