Skip to content

Commit

Permalink
Merge branch 'release/0.4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
msaps committed Feb 27, 2017
2 parents 40a06f8 + dfb906b commit c45de5c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Example/Pageboy-Example/PageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource
willScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {

self.updateBarButtonStates(index: index)
}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPosition position: CGPoint,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {

self.updateAppearance(pageOffset: position.x)
self.updateStatusLabels()
}
Expand All @@ -128,6 +130,7 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource
didScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {

self.updateAppearance(pageOffset: CGFloat(index))
self.updateStatusLabels()

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 = "0.4.4"
s.version = "0.4.5"
s.summary = "A simple, highly informative page view controller."
s.description = <<-DESC
Pageboy is a page view controller that provides simplified data source management, enhanced delegation and other useful features.
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>0.4.4</string>
<string>0.4.5</string>
<key>CFBundleVersion</key>
<string>AUTO_GENERATED</string>
<key>NSPrincipalClass</key>
Expand Down
17 changes: 13 additions & 4 deletions Sources/Pageboy/PageboyScrollDetection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg

public func pageViewController(_ pageViewController: UIPageViewController,
willTransitionTo pendingViewControllers: [UIViewController]) {
self.pageViewController(pageViewController,
willTransitionTo: pendingViewControllers,
animated: false)
}

internal func pageViewController(_ pageViewController: UIPageViewController,
willTransitionTo pendingViewControllers: [UIViewController],
animated: Bool) {
guard let viewController = pendingViewControllers.first,
let index = self.viewControllers?.index(of: viewController) else {
return
return
}

self.expectedTransitionIndex = index
let direction = NavigationDirection.forPage(index, previousPage: self.currentIndex ?? index)
self.delegate?.pageboyViewController(self, willScrollToPageAtIndex: index,
direction: direction,
animated: false)
animated: animated)
}

public func pageViewController(_ pageViewController: UIPageViewController,
Expand Down Expand Up @@ -72,8 +80,8 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg
return
}

// do not continue if previous offset equals current
if previousPagePosition == pageOffset {
// do not continue if previous position equals current
if previousPagePosition == pagePosition {
return
}

Expand Down Expand Up @@ -159,6 +167,7 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg

let isOnPage = pagePosition.truncatingRemainder(dividingBy: 1) == 0
if isOnPage {
guard currentIndex != self.currentIndex else { return false}
self.currentIndex = currentIndex
}

Expand Down
5 changes: 3 additions & 2 deletions Sources/Pageboy/PageboyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,10 @@ open class PageboyViewController: UIViewController {

let direction = NavigationDirection.forPage(rawIndex, previousPage: self.currentIndex ?? rawIndex)
self.pageViewController(self.pageViewController,
willTransitionTo: [viewController])
willTransitionTo: [viewController],
animated: animated)

self.isScrollingAnimated = true
self.isScrollingAnimated = animated
self.pageViewController.setViewControllers([viewController],
direction: direction.pageViewControllerNavDirection,
animated: animated,
Expand Down
37 changes: 36 additions & 1 deletion Sources/PageboyTests/PageboyTransitionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class PageboyTransitionTests: PageboyTests {
"Not reporting partial user interacted transition direction values correctly.")
}

/// Test unsuccessful animated transition to current page
/// Test unsuccessful animated transition to current page.
func testUnsuccessfulTransitionToCurrentPage() {
self.dataSource.numberOfPages = 5
self.pageboyViewController.dataSource = self.dataSource
Expand All @@ -163,4 +163,39 @@ class PageboyTransitionTests: PageboyTests {
"Not handling unsuccessful transition to current page correctly.")
}
}

/// Test animated flags are correct for animated transitions.
func testAnimatedTransitionAnimatedFlags() {
self.dataSource.numberOfPages = 5
self.pageboyViewController.dataSource = self.dataSource
let transitionIndex = 3

self.pageboyViewController.scrollToPage(.atIndex(index: transitionIndex), animated: true)
{ (newViewController, animated, finished) in

XCTAssert(self.pageboyViewController.currentIndex == transitionIndex &&
self.delegate.lastWillScrollToPageAnimated == true &&
self.delegate.lastDidScrollToPageAtIndexAnimated == true &&
self.delegate.lastDidScrollToPositionAnimated == true,
"Animated flags for an animated scrollToPage are incorrect.")
}
}

/// Test animated flags are correct for non-animated transitions.
func testNonAnimatedTransitionAnimatedFlags() {
self.dataSource.numberOfPages = 5
self.pageboyViewController.dataSource = self.dataSource
let transitionIndex = 3

self.pageboyViewController.scrollToPage(.atIndex(index: transitionIndex), animated: false)
{ (newViewController, animated, finished) in

XCTAssert(self.pageboyViewController.currentIndex == transitionIndex &&
self.delegate.lastWillScrollToPageAnimated == false &&
self.delegate.lastDidScrollToPageAtIndexAnimated == false &&
self.delegate.lastDidScrollToPositionAnimated == false,
"Animated flags for an non animated scrollToPage are incorrect.")
}
}

}
7 changes: 7 additions & 0 deletions Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ class TestPageboyDelegate: PageboyViewControllerDelegate {
var lastRecordedPageIndex: Int?
var lastRecordedDirection: PageboyViewController.NavigationDirection?

var lastWillScrollToPageAnimated: Bool?
var lastDidScrollToPositionAnimated: Bool?
var lastDidScrollToPageAtIndexAnimated: Bool?

func pageboyViewController(_ pageboyViewController: PageboyViewController,
willScrollToPageAtIndex pageIndex: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
lastWillScrollToPageAnimated = animated
}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPosition pagePosition: CGPoint,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
lastDidScrollToPositionAnimated = animated
lastRecordedPagePosition = pagePosition
lastRecordedDirection = direction
}
Expand All @@ -33,6 +39,7 @@ class TestPageboyDelegate: PageboyViewControllerDelegate {
didScrollToPageAtIndex pageIndex: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
lastDidScrollToPageAtIndexAnimated = animated
lastRecordedPageIndex = pageIndex
lastRecordedDirection = direction
}
Expand Down

0 comments on commit c45de5c

Please sign in to comment.