Skip to content
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

Expose methods to @objc when needed #52

Merged
merged 1 commit into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/PagesDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PODS:
- SwiftHash (~> 2.0.0)
- Imaginary (3.0.0):
- Cache (~> 4.0)
- Pages (2.0.0)
- Pages (2.0.1)
- SwiftHash (2.0.0)

DEPENDENCIES:
Expand All @@ -17,7 +17,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Cache: 22f55fa3ab1b41e75799b479346b50b428fc5529
Imaginary: 2765d293d425cbed3b07fa11642554cbaebe913d
Pages: ed64dfa45562f9ce817f70af93361692975e7572
Pages: 56615e95dc00943349de5a83f550953f3446c0e7
SwiftHash: d2e09b13495447178cdfb8e46e54a5c46f15f5a9

PODFILE CHECKSUM: 704ea1ed834c6bde37b6188e9105c11f86c1ca77
Expand Down
51 changes: 27 additions & 24 deletions Source/PagesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,27 @@ import UIKit
}
}
}
}

// MARK: - Public methods
// MARK: - Public methods

extension PagesController {
open func goTo(_ index: Int) {
if index >= 0 && index < pages.count {
let direction: UIPageViewControllerNavigationDirection = (index > currentIndex) ? .forward : .reverse
let viewController = pages[index]
currentIndex = index
setViewControllers([viewController],

setViewControllers(
[viewController],
direction: direction,
animated: true,
completion: { [unowned self] finished in
self.pagesDelegate?.pageViewController(self,
self.pagesDelegate?.pageViewController(
self,
setViewController: viewController,
atPage: self.currentIndex)
})
atPage: self.currentIndex
)
})

if setNavigationTitle {
title = viewController.title
}
Expand All @@ -124,35 +127,35 @@ extension PagesController {

// MARK: - UIPageViewControllerDataSource

extension PagesController : UIPageViewControllerDataSource {
open func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController? {
extension PagesController: UIPageViewControllerDataSource {
@objc open func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController? {
let index = prevIndex(viewControllerIndex(viewController))
return pages.at(index)
}

open func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController? {
@objc open func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController? {
let index: Int? = nextIndex(viewControllerIndex(viewController))
return pages.at(index)
}

open func presentationCount(for pageViewController: UIPageViewController) -> Int {
@objc open func presentationCount(for pageViewController: UIPageViewController) -> Int {
return showPageControl ? pages.count : 0
}

open func presentationIndex(for pageViewController: UIPageViewController) -> Int {
@objc open func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return showPageControl ? currentIndex : 0
}
}

// MARK: - UIPageViewControllerDelegate

extension PagesController : UIPageViewControllerDelegate {
open func pageViewController(_ pageViewController: UIPageViewController,
didFinishAnimating finished: Bool,
previousViewControllers: [UIViewController],
transitionCompleted completed: Bool) {
extension PagesController: UIPageViewControllerDelegate {
@objc open func pageViewController(_ pageViewController: UIPageViewController,
didFinishAnimating finished: Bool,
previousViewControllers: [UIViewController],
transitionCompleted completed: Bool) {
guard completed else {
return
}
Expand Down Expand Up @@ -181,12 +184,12 @@ extension PagesController : UIPageViewControllerDelegate {

// MARK: - Private methods

extension PagesController {
private extension PagesController {
func viewControllerIndex(_ viewController: UIViewController) -> Int? {
return pages.index(of: viewController)
}

private func toggle() {
func toggle() {
for subview in view.subviews {
if let subview = subview as? UIScrollView {
subview.isScrollEnabled = enableSwipe
Expand All @@ -195,7 +198,7 @@ extension PagesController {
}
}

private func addViewController(_ viewController: UIViewController) {
func addViewController(_ viewController: UIViewController) {
pages.append(viewController)

if pages.count == 1 {
Expand All @@ -213,7 +216,7 @@ extension PagesController {
}
}

private func addConstraints() {
func addConstraints() {
view.addConstraint(NSLayoutConstraint(item: bottomLineView, attribute: .bottom,
relatedBy: .equal, toItem: view, attribute: .bottom,
multiplier: 1, constant: -Dimensions.bottomLineBottomMargin))
Expand All @@ -232,7 +235,7 @@ extension PagesController {
}
}

// MARK: Storyboard
// MARK: - Storyboard

extension PagesController {
public convenience init(_ storyboardIds: [String], storyboard: UIStoryboard = .Main) {
Expand Down