Skip to content

Commit

Permalink
Merge branch 'release/0.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
msaps committed Feb 23, 2017
2 parents 1aadf55 + e05b271 commit 798fe31
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 33 deletions.
21 changes: 12 additions & 9 deletions Example/Pageboy-Example/PageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,24 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource
//

func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPosition position: CGPoint,
direction: PageboyViewController.NavigationDirection) {
self.updateAppearance(pageOffset: position.x)
self.updateStatusLabels()
willScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
self.updateBarButtonStates(index: index)
}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
willScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection) {
self.updateBarButtonStates(index: index)
didScrollToPosition position: CGPoint,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
self.updateAppearance(pageOffset: position.x)
self.updateStatusLabels()
}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPageWithIndex index: Int,
direction: PageboyViewController.NavigationDirection) {
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.2"
s.version = "0.4.3"
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Called when the page view controller is about to embark on a transition to a new
```swift
func pageboyViewController(_ pageboyViewController: PageboyViewController,
willScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection)
direction: PageboyViewController.NavigationDirection,
animated: Bool)
```

#### didScrollToPosition
Expand All @@ -82,8 +83,9 @@ Called when the page view controller did successfully complete a scroll transiti

```swift
func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPageWithIndex index: Int,
direction: PageboyViewController.NavigationDirection)
didScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool)
```

## Additional functionality
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.2</string>
<string>0.4.3</string>
<key>CFBundleVersion</key>
<string>AUTO_GENERATED</string>
<key>NSPrincipalClass</key>
Expand Down
10 changes: 8 additions & 2 deletions Sources/Pageboy/PageboyScrollDetection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg

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

public func pageViewController(_ pageViewController: UIPageViewController,
Expand Down Expand Up @@ -85,10 +87,14 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg
} else {
positionPoint = CGPoint(x: scrollView.contentOffset.x, y: pagePosition)
}

// ignore duplicate updates
guard self.currentPosition != positionPoint else { return }
self.currentPosition = positionPoint
self.delegate?.pageboyViewController(self,
didScrollToPosition: positionPoint,
direction: direction)
direction: direction,
animated: self.isScrollingAnimated)

self.previousPagePosition = pagePosition
}
Expand Down
37 changes: 28 additions & 9 deletions Sources/Pageboy/PageboyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,35 @@ public protocol PageboyViewControllerDelegate {
/// - pageboyViewController: The Pageboy view controller.
/// - index: The new page index.
/// - direction: The direction of the scroll.
/// - animation: Whether the scroll will be animated.
func pageboyViewController(_ pageboyViewController: PageboyViewController,
willScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection)
direction: PageboyViewController.NavigationDirection,
animated: Bool)

/// The page view controller did scroll to an offset between pages.
///
/// - Parameters:
/// - pageboyViewController: The Pageboy view controller.
/// - position: The current relative page position.
/// - direction: The direction of the scroll.
/// - animated: Whether the scroll is being animated.
func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPosition position: CGPoint,
direction: PageboyViewController.NavigationDirection)
direction: PageboyViewController.NavigationDirection,
animated: Bool)

/// The page view controller did complete scroll to a new page.
///
/// - Parameters:
/// - pageboyViewController: The Pageboy view controller.
/// - index: The new page index.
/// - direction: The direction of the scroll.
/// - animation: Whether the scroll was animated.
func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPageWithIndex index: Int,
direction: PageboyViewController.NavigationDirection)
didScrollToPageAtIndex index: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool)
}

open class PageboyViewController: UIViewController {
Expand Down Expand Up @@ -170,16 +176,16 @@ open class PageboyViewController: UIViewController {
public internal(set) var currentIndex: Int? {
didSet {
guard let currentIndex = self.currentIndex else { return }
guard currentIndex != oldValue else { return }

// ensure position keeps in sync
self.currentPosition = CGPoint(x: self.navigationOrientation == .horizontal ? CGFloat(currentIndex) : 0.0,
y: self.navigationOrientation == .vertical ? CGFloat(currentIndex) : 0.0)
let direction = NavigationDirection.forPosition(CGFloat(currentIndex),
previous: CGFloat(oldValue ?? currentIndex))
self.delegate?.pageboyViewController(self,
didScrollToPageWithIndex: currentIndex,
direction: direction)
didScrollToPageAtIndex: currentIndex,
direction: direction,
animated: self.isScrollingAnimated)
}
}

Expand Down Expand Up @@ -207,6 +213,17 @@ open class PageboyViewController: UIViewController {
self.setUpPageViewController()
}

open override func viewWillTransition(to size: CGSize,
with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

// ignore scroll updates during orientation change
self.pageViewController.scrollView?.delegate = nil
coordinator.animate(alongsideTransition: nil) { (context) in
self.pageViewController.scrollView?.delegate = self
}
}

//
// MARK: Page management
//
Expand Down Expand Up @@ -245,7 +262,8 @@ open class PageboyViewController: UIViewController {
let direction = NavigationDirection.forPage(rawIndex, previousPage: self.currentIndex ?? rawIndex)
self.delegate?.pageboyViewController(self,
willScrollToPageAtIndex: rawIndex,
direction: direction)
direction: direction,
animated: animated)

self.isScrollingAnimated = true
self.pageViewController.setViewControllers([viewController],
Expand All @@ -263,7 +281,8 @@ open class PageboyViewController: UIViewController {
if !animated {
self.delegate?.pageboyViewController(self,
didScrollToPosition: self.currentPosition!,
direction: direction)
direction: direction,
animated: animated)
}
}
completion?(viewController, animated, finished)
Expand Down
19 changes: 11 additions & 8 deletions Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ class TestPageboyDelegate: PageboyViewControllerDelegate {
var lastRecordedDirection: PageboyViewController.NavigationDirection?

func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPosition pagePosition: CGPoint,
direction: PageboyViewController.NavigationDirection) {
lastRecordedPagePosition = pagePosition
lastRecordedDirection = direction
willScrollToPageAtIndex pageIndex: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
willScrollToPageAtIndex pageIndex: Int,
direction: PageboyViewController.NavigationDirection) {
didScrollToPosition pagePosition: CGPoint,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
lastRecordedPagePosition = pagePosition
lastRecordedDirection = direction
}

func pageboyViewController(_ pageboyViewController: PageboyViewController,
didScrollToPageWithIndex pageIndex: Int,
direction: PageboyViewController.NavigationDirection) {
didScrollToPageAtIndex pageIndex: Int,
direction: PageboyViewController.NavigationDirection,
animated: Bool) {
lastRecordedPageIndex = pageIndex
lastRecordedDirection = direction
}
Expand Down

0 comments on commit 798fe31

Please sign in to comment.