Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Barreto committed Jan 29, 2016
1 parent 8784865 commit 2c88f94
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Example/Example/BarExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class BarExampleViewController: BarPagerTabStripViewController {
override func reloadPagerTabStripView() {
isReload = true
if rand() % 2 == 0 {
pagerBehaviour = .Progressive(skipIntermediteViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
}
else {
pagerBehaviour = .Common(skipIntermediteViewControllers: rand() % 2 == 0)
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
}
super.reloadPagerTabStripView()
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Example/ButtonBarExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
override func reloadPagerTabStripView() {
isReload = true
if rand() % 2 == 0 {
pagerBehaviour = .Progressive(skipIntermediteViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
}
else {
pagerBehaviour = .Common(skipIntermediteViewControllers: rand() % 2 == 0)
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
}
super.reloadPagerTabStripView()
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Example/NavButtonBarExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class NavButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
override func reloadPagerTabStripView() {
isReload = true
if rand() % 2 == 0 {
pagerBehaviour = .Progressive(skipIntermediteViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
}
else {
pagerBehaviour = .Common(skipIntermediteViewControllers: rand() % 2 == 0)
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
}
super.reloadPagerTabStripView()
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/SegmentedExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SegmentedExampleViewController: SegmentedPagerTabStripViewController {

@IBAction func reloadTapped(sender: UIBarButtonItem) {
isReload = true
pagerBehaviour = .Common(skipIntermediteViewControllers: rand() % 2 == 0)
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
pagerBehaviour.skipIntermediateViewControllers
reloadPagerTabStripView()
}
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,37 @@ That's it! We're done! 🍻🍻

## Customization

The pager indicator can be updated progressive as we swipe or at once in the middle of the transition between the view controllers.
By setting up `pagerBehaviour` property we can choose how the indicator should be updated.

```swift
public var pagerBehaviour: PagerTabStripBehaviour
```

```swift
public enum PagerTabStripBehaviour {
case Common(skipIntermediteViewControllers: Bool)
case Progressive(skipIntermediteViewControllers: Bool, elasticIndicatorLimit: Bool)
}
```

Default Values:
```swift
// Twitter Type
PagerTabStripBehaviour.Common(skipIntermediteViewControllers: true)
// Segmented Type
PagerTabStripBehaviour.Common(skipIntermediteViewControllers: true)
// Bar Type
PagerTabStripBehaviour.Progressive(skipIntermediteViewControllers: true, elasticIndicatorLimit: true)
// ButtonBar Type
PagerTabStripBehaviour.Progressive(skipIntermediteViewControllers: true, elasticIndicatorLimit: true)`
```

As you may've noticed `Common` and `Progressive` enumeration cases has `skipIntermediteViewControllers` and `elasticIndicatorLimit` associated values.

`skipIntermediteViewControllers` allows us to skip intermediate view controllers when a tab indicator is tapped.

`elasticIndicatorLimit` allows us to tension the indicator when we reach a limit, I mean when we try to move forward from last indicator or move back from first indicator.

## Requirements

Expand Down
12 changes: 6 additions & 6 deletions Sources/PagerTabStripBehaviour.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import Foundation

public enum PagerTabStripBehaviour {

case Common(skipIntermediteViewControllers: Bool)
case Progressive(skipIntermediteViewControllers: Bool, elasticIndicatorLimit: Bool)
case Common(skipIntermediateViewControllers: Bool)
case Progressive(skipIntermediateViewControllers: Bool, elasticIndicatorLimit: Bool)

public var skipIntermediateViewControllers: Bool {
switch self {
case .Common(let skipIntermediteControllers):
return skipIntermediteControllers
case .Progressive(let skipIntermediteControllers, _):
return skipIntermediteControllers
case .Common(let skipIntermediateViewControllers):
return skipIntermediateViewControllers
case .Progressive(let skipIntermediateViewControllers, _):
return skipIntermediateViewControllers
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/PagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PagerTabStripViewController: UIViewController, UIScrollViewDelegate
public weak var delegate: PagerTabStripDelegate?
public weak var datasource: PagerTabStripDataSource?

public var pagerBehaviour = PagerTabStripBehaviour.Progressive(skipIntermediteViewControllers: true, elasticIndicatorLimit: true)
public var pagerBehaviour = PagerTabStripBehaviour.Progressive(skipIntermediateViewControllers: true, elasticIndicatorLimit: true)

public private(set) var viewControllers = [UIViewController]()
public private(set) var currentIndex = 0
Expand Down
2 changes: 2 additions & 0 deletions Sources/SegmentedPagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ public class SegmentedPagerTabStripViewController: PagerTabStripViewController,

public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
pagerBehaviour = PagerTabStripBehaviour.Common(skipIntermediateViewControllers: true)
delegate = self
datasource = self
}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
pagerBehaviour = PagerTabStripBehaviour.Common(skipIntermediateViewControllers: true)
delegate = self
datasource = self
}
Expand Down
8 changes: 8 additions & 0 deletions Sources/TwitterPagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ public class TwitterPagerTabStripViewController: PagerTabStripViewController, Pa

public var settings = TwitterPagerTabStripSettings()

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

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
pagerBehaviour = PagerTabStripBehaviour.Common(skipIntermediateViewControllers: true)
delegate = self
datasource = self
}
Expand Down

0 comments on commit 2c88f94

Please sign in to comment.