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

Convert XLPagerTabStrip to Swift 3 #226

Merged
merged 3 commits into from
Sep 16, 2016
Merged
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
Next Next commit
Swift3 Xcode8 GM Conversion
  • Loading branch information
Tomas Radvansky authored and mats-claassen committed Sep 14, 2016
commit 49f963b687a9cb3cdfe8bc405a431b3d264911b5
29 changes: 15 additions & 14 deletions Sources/BarPagerTabStripViewController.swift
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
// THE SOFTWARE.

import Foundation
import UIKit

public struct BarPagerTabStripSettings {

@@ -35,25 +36,25 @@ public struct BarPagerTabStripSettings {
public var style = Style()
}

public class BarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate {
open class BarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate {

public var settings = BarPagerTabStripSettings()
open var settings = BarPagerTabStripSettings()

@IBOutlet lazy public var barView: BarView! = { [unowned self] in
let barView = BarView(frame: CGRectMake(0, 0, self.view.frame.size.width, self.settings.style.barHeight))
barView.autoresizingMask = .FlexibleWidth
barView.backgroundColor = .blackColor()
barView.selectedBar.backgroundColor = .whiteColor()
@IBOutlet lazy open var barView: BarView! = { [unowned self] in
let barView = BarView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.settings.style.barHeight))
barView.autoresizingMask = .flexibleWidth
barView.backgroundColor = .black
barView.selectedBar.backgroundColor = .white
return barView
}()

public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
delegate = self
datasource = self
}

public override func viewDidLoad() {
open override func viewDidLoad() {
super.viewDidLoad()
barView.backgroundColor = self.settings.style.barBackgroundColor ?? barView.backgroundColor
barView.selectedBar.backgroundColor = self.settings.style.selectedBarBackgroundColor ?? barView.selectedBar.backgroundColor
@@ -65,7 +66,7 @@ public class BarPagerTabStripViewController: PagerTabStripViewController, PagerT
datasource = self
}

public override func viewWillAppear(animated: Bool) {
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if barView.superview == nil {
view.addSubview(barView)
@@ -74,21 +75,21 @@ public class BarPagerTabStripViewController: PagerTabStripViewController, PagerT
barView.moveToIndex(index: currentIndex, animated: false)
}

public override func reloadPagerTabStripView() {
open override func reloadPagerTabStripView() {
super.reloadPagerTabStripView()
barView.optionsCount = viewControllers.count
if isViewLoaded(){
if isViewLoaded{
barView.moveToIndex(index: currentIndex, animated: false)
}
}

// MARK: - PagerTabStripDelegate

public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) {
open func pagerTabStripViewController(_ pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int) {
Copy link
Member

Choose a reason for hiding this comment

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

updateIndicator(for pagerTabStripViewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int)

barView.moveToIndex(index: toIndex, animated: true)
}

public func pagerTabStripViewController(pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
open func pagerTabStripViewController(_ pagerTabStripViewController: PagerTabStripViewController, updateIndicatorFromIndex fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
Copy link
Member

Choose a reason for hiding this comment

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

same here

barView.moveToIndex(fromIndex: fromIndex, toIndex: toIndex, progressPercentage: progressPercentage)
}
}
16 changes: 8 additions & 8 deletions Sources/BarView.swift
Original file line number Diff line number Diff line change
@@ -24,10 +24,10 @@

import Foundation

public class BarView: UIView {
open class BarView: UIView {

public lazy var selectedBar: UIView = { [unowned self] in
let selectedBar = UIView(frame: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height))
open lazy var selectedBar: UIView = { [unowned self] in
let selectedBar = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))
return selectedBar
}()

@@ -53,12 +53,12 @@ public class BarView: UIView {

// MARK: - Helpers

private func updateSelectedBarPositionWithAnimation(animation: Bool) {
fileprivate func updateSelectedBarPositionWithAnimation(_ animation: Bool) {
Copy link
Member

@mtnbarreto mtnbarreto Sep 16, 2016

Choose a reason for hiding this comment

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

refactor signature

updateSelectedBarPosition(withAnimation: )

var frame = selectedBar.frame
frame.size.width = self.frame.size.width / CGFloat(optionsCount)
frame.origin.x = frame.size.width * CGFloat(selectedIndex)
if animation {
UIView.animateWithDuration(0.3, animations: { [weak self] in
UIView.animate(withDuration: 0.3, animations: { [weak self] in
self?.selectedBar.frame = frame
})
}
@@ -67,12 +67,12 @@ public class BarView: UIView {
}
}

public func moveToIndex(index index: Int, animated: Bool) {
open func moveToIndex(index: Int, animated: Bool) {
Copy link
Member

Choose a reason for hiding this comment

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

moveTo(index: ...)

selectedIndex = index
updateSelectedBarPositionWithAnimation(animated)
}

public func moveToIndex(fromIndex fromIndex: Int, toIndex: Int, progressPercentage: CGFloat) {
open func moveToIndex(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat) {
Copy link
Member

@mtnbarreto mtnbarreto Sep 16, 2016

Choose a reason for hiding this comment

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

moveTo(index: Int, fromIndex: Int, progressPercentage: CGFloat

it may also be moveTo(index: Int, from: Int, withProgressPercentage: CGFloat

selectedIndex = (progressPercentage > 0.5) ? toIndex : fromIndex

var newFrame = selectedBar.frame
@@ -86,7 +86,7 @@ public class BarView: UIView {
selectedBar.frame = targetFrame
}

public override func layoutSubviews() {
open override func layoutSubviews() {
super.layoutSubviews()
updateSelectedBarPositionWithAnimation(false)
}
Loading