Skip to content

Commit

Permalink
Merge pull request #60 from uias/develop
Browse files Browse the repository at this point in the history
1.0.9 Release
  • Loading branch information
msaps authored May 29, 2017
2 parents 6f627f7 + 3b51ba2 commit 4617ac4
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ script:
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
email: false
email: false
branches:
only:
- master
- develop
9 changes: 9 additions & 0 deletions Example/Pageboy-Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<array>
<string>armv7</string>
</array>
<key>UIRequiresFullScreen</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UISupportedInterfaceOrientations</key>
Expand All @@ -38,6 +40,13 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
Expand Down
7 changes: 3 additions & 4 deletions Example/Pageboy-Example/PageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource
func pageboyViewController(_ pageboyViewController: PageboyViewController,
willScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {

self.updateBarButtonStates(index: index)
}
animated: Bool) {}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPosition position: CGPoint,
Expand All @@ -124,6 +121,8 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource

self.updateAppearance(pageOffset: position.x)
self.updateStatusLabels()

self.updateBarButtonStates(index: pageboyViewController.currentIndex ?? 0)
}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
Expand Down
2 changes: 1 addition & 1 deletion Pageboy.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pod::Spec.new do |s|
s.platform = :ios, "9.0"
s.requires_arc = true

s.version = "1.0.8"
s.version = "1.0.9"
s.summary = "A simple, highly informative page view controller."
s.description = <<-DESC
A page view controller that provides simplified data source management, enhanced delegation and other useful features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,51 @@

import Foundation

// MARK: - Paging Set Up and Configuration
internal extension PageboyViewController {

// MARK: Set Up

/// Set up inner UIPageViewController ready for displaying pages.
///
/// - Parameter reloadViewControllers: Reload the view controllers data source for the PageboyViewController.
internal func setUpPageViewController(reloadViewControllers: Bool = true) {
if self.pageViewController != nil { // destroy existing page VC
self.pageViewController?.view.removeFromSuperview()
self.pageViewController?.removeFromParentViewController()
self.pageViewController = nil
}

let pageViewController = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: self.navigationOrientation,
options: nil)
pageViewController.delegate = self
pageViewController.dataSource = self
self.pageViewController = pageViewController

self.addChildViewController(pageViewController)
self.view.addSubview(pageViewController.view)
pageViewController.view.pageboyPinToSuperviewEdges()
self.view.sendSubview(toBack: pageViewController.view)
pageViewController.didMove(toParentViewController: self)

pageViewController.scrollView?.delegate = self

self.pageViewController.view.backgroundColor = .clear

self.reloadPages(reloadViewControllers: reloadViewControllers)
}

/// Reload the pages in the PageboyViewController
///
/// - Parameter reloadViewControllers: Reload the view controller data source.
internal func reloadPages(reloadViewControllers: Bool) {

if reloadViewControllers || self.viewControllers == nil {
self.viewControllers = self.dataSource?.viewControllers(forPageboyViewController: self)
}
let defaultIndex = self.dataSource?.defaultPageIndex(forPageboyViewController: self) ?? .first
let defaultIndexValue = self.indexValue(forPageIndex: defaultIndex)
let defaultIndexValue = self.indexValue(for: defaultIndex)

guard defaultIndexValue < self.viewControllers?.count ?? 0,
let viewController = self.viewControllers?[defaultIndexValue] else {
Expand All @@ -34,6 +70,49 @@ internal extension PageboyViewController {
didReload: viewControllers,
currentIndex: defaultIndex)
}

// MARK: Utilities

/// Convert a PageIndex to a raw index integer.
///
/// - Parameter pageIndex: The page index to translate.
/// - Returns: The raw index integer.
internal func indexValue(for pageIndex: PageIndex) -> Int {
switch pageIndex {

case .next:
guard let currentIndex = self.currentIndex else {
return 0
}
var proposedIndex = currentIndex + 1
if self.isInfiniteScrollEnabled && proposedIndex == self.viewControllers?.count { // scroll back to first index
proposedIndex = 0
}
return proposedIndex

case .previous:
guard let currentIndex = self.currentIndex else {
return 0
}
var proposedIndex = currentIndex - 1
if self.isInfiniteScrollEnabled && proposedIndex < 0 { // scroll to last index
proposedIndex = (self.viewControllers?.count ?? 1) - 1
}
return proposedIndex

case .first:
return 0

case .last:
return (self.viewControllers?.count ?? 1) - 1

case .atIndex(let index):
return index

case .at(let index):
return index
}
}
}

// MARK: - UIPageViewControllerDataSource, PageboyViewControllerDataSource
Expand Down
2 changes: 1 addition & 1 deletion Sources/Pageboy/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.8</string>
<string>1.0.9</string>
<key>CFBundleVersion</key>
<string>AUTO_GENERATED</string>
<key>NSPrincipalClass</key>
Expand Down
119 changes: 24 additions & 95 deletions Sources/Pageboy/PageboyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public protocol PageboyViewControllerDelegate: class {
currentIndex: PageboyViewController.PageIndex)
}

/// A simple, highly informative page view controller.
open class PageboyViewController: UIViewController {

//
Expand All @@ -96,7 +97,7 @@ open class PageboyViewController: UIViewController {
/// - previous: The previous page if available.
/// - first: The first page.
/// - last: The last page.
/// - atIndex: A custom specified page index.
/// - at: A custom specified page index.
public enum PageIndex {
case next
case previous
Expand Down Expand Up @@ -161,25 +162,22 @@ open class PageboyViewController: UIViewController {
/// The object that is the delegate for the page view controller.
public weak var delegate: PageboyViewControllerDelegate?

/// Whether scroll is enabled on the page view controller.
///
/// Default is TRUE.
public var isScrollEnabled: Bool = true {
didSet {
self.pageViewController.scrollView?.isScrollEnabled = isScrollEnabled
}
}

/// Whether the page view controller is currently being touched.
public var isTracking: Bool {
return self.pageViewController.scrollView?.isTracking ?? false
}

/// Whether the page view controller is currently being dragged.
public var isDragging: Bool {
return self.pageViewController.scrollView?.isDragging ?? false
}

// default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses
public var delaysContentTouches: Bool {
set {
self.pageViewController.scrollView?.delaysContentTouches = newValue
} get {
return self.pageViewController.scrollView?.delaysContentTouches ?? false
}
}
/// default YES. if YES, bounces past edge of content and back again.
public var bounces: Bool = true

Expand All @@ -191,14 +189,14 @@ open class PageboyViewController: UIViewController {
self.pageViewController.scrollView?.isUserInteractionEnabled = isUserInteractionEnabled
}
}

/// Whether the page view controller is currently animating a scroll between pages.
private(set) var isScrollingAnimated = false {
/// Whether scroll is enabled on the page view controller.
///
/// Default is TRUE.
public var isScrollEnabled: Bool = true {
didSet {
self.isUserInteractionEnabled = !self.isScrollingAnimated
self.pageViewController.scrollView?.isScrollEnabled = isScrollEnabled
}
}

/// Whether the page view controller should infinitely scroll at the end of page ranges.
///
/// Default is FALSE.
Expand All @@ -208,6 +206,13 @@ open class PageboyViewController: UIViewController {
}
}

/// Whether the page view controller is currently animating a scroll between pages.
private(set) var isScrollingAnimated = false {
didSet {
self.isUserInteractionEnabled = !self.isScrollingAnimated
}
}

/// The view controllers that are displayed in the page view controller.
public internal(set) var viewControllers: [UIViewController]?

Expand Down Expand Up @@ -293,7 +298,7 @@ open class PageboyViewController: UIViewController {
}

//
// MARK: Transitioning
// MARK: Scrolling
//

/// Scroll the page view controller to a new page.
Expand All @@ -309,7 +314,7 @@ open class PageboyViewController: UIViewController {
guard self.isScrollingAnimated == false else { return }
guard self.isTracking == false else { return }

let rawIndex = self.indexValue(forPageIndex: pageIndex )
let rawIndex = self.indexValue(for: pageIndex )
if rawIndex != self.currentIndex {

// guard against invalid page indexing
Expand Down Expand Up @@ -367,79 +372,3 @@ open class PageboyViewController: UIViewController {
}

}

// MARK: - Page view controller Set up & Utilities
internal extension PageboyViewController {

//
// MARK: Set Up
//

internal func setUpPageViewController(reloadViewControllers: Bool = true) {
if self.pageViewController != nil { // destroy existing page VC
self.pageViewController?.view.removeFromSuperview()
self.pageViewController?.removeFromParentViewController()
self.pageViewController = nil
}

let pageViewController = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: self.navigationOrientation,
options: nil)
pageViewController.delegate = self
pageViewController.dataSource = self
self.pageViewController = pageViewController

self.addChildViewController(pageViewController)
self.view.addSubview(pageViewController.view)
pageViewController.view.pageboyPinToSuperviewEdges()
self.view.sendSubview(toBack: pageViewController.view)
pageViewController.didMove(toParentViewController: self)

pageViewController.scrollView?.delegate = self

self.pageViewController.view.backgroundColor = .clear

self.reloadPages(reloadViewControllers: reloadViewControllers)
}

//
// MARK: Utilities
//

internal func indexValue(forPageIndex pageIndex: PageIndex) -> Int {
switch pageIndex {

case .next:
guard let currentIndex = self.currentIndex else {
return 0
}
var proposedIndex = currentIndex + 1
if self.isInfiniteScrollEnabled && proposedIndex == self.viewControllers?.count { // scroll back to first index
proposedIndex = 0
}
return proposedIndex

case .previous:
guard let currentIndex = self.currentIndex else {
return 0
}
var proposedIndex = currentIndex - 1
if self.isInfiniteScrollEnabled && proposedIndex < 0 { // scroll to last index
proposedIndex = (self.viewControllers?.count ?? 1) - 1
}
return proposedIndex

case .first:
return 0

case .last:
return (self.viewControllers?.count ?? 1) - 1

case .atIndex(let index):
return index

case .at(let index):
return index
}
}
}

0 comments on commit 4617ac4

Please sign in to comment.