-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
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) { | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
barView.moveToIndex(fromIndex: fromIndex, toIndex: toIndex, progressPercentage: progressPercentage) | ||
} | ||
} |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor signature
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
selectedIndex = index | ||
updateSelectedBarPositionWithAnimation(animated) | ||
} | ||
|
||
public func moveToIndex(fromIndex fromIndex: Int, toIndex: Int, progressPercentage: CGFloat) { | ||
open func moveToIndex(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
it may also be |
||
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) | ||
} | ||
|
There was a problem hiding this comment.
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)