Skip to content
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
20 changes: 10 additions & 10 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 @@ -303,7 +303,7 @@ extension TabView: UICollectionViewDataSource {
cell.option = option
cell.isCurrent = fixedIndex == (currentIndex % pageTabItemsCount)
cell.tabItemButtonPressedBlock = { [weak self, weak cell] in
var direction: UIPageViewControllerNavigationDirection = .forward
var direction: UIPageViewController.NavigationDirection = .forward
if let pageTabItemsCount = self?.pageTabItemsCount, let currentIndex = self?.currentIndex {
if self?.isInfinity == true {
if (indexPath.item < pageTabItemsCount) || (indexPath.item < currentIndex) {
Expand Down
11 changes: 8 additions & 3 deletions TabPageViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
F8CE39F81F35AE6500CF74BA /* InfiniteTabPageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InfiniteTabPageViewController.swift; path = Demo/TabPageViewControllerDemo/InfiniteTabPageViewController.swift; sourceTree = "<group>"; };
OBJ_12 /* TabPageViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabPageViewControllerTests.swift; sourceTree = "<group>"; };
OBJ_14 /* TabPageViewController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = TabPageViewController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_15 /* TabPageViewControllerTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = TabPageViewControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_15 /* TabPageViewControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = TabPageViewControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_9 /* TabPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabPageViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down 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 All @@ -539,6 +542,7 @@
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_VERSION = 5.0;
TARGET_NAME = TabPageViewControllerTests;
};
name = Debug;
Expand All @@ -556,6 +560,7 @@
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_VERSION = 5.0;
TARGET_NAME = TabPageViewControllerTests;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
15 changes: 0 additions & 15 deletions Tests/TabPageViewControllerTests/TabPageViewControllerTests.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
import XCTest
@testable import TabPageViewController

class TabPageViewControllerTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
XCTAssertEqual(TabPageViewController().text, "Hello, World!")
}


static var allTests : [(String, (TabPageViewControllerTests) -> () throws -> Void)] {
return [
("testExample", testExample),
]
}
}