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

Previewdidload selection #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions Sources/PagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {

open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if !didCallViewWillAppearOnce {
updateContent()
didCallViewWillAppearOnce = true
}
isViewAppearing = true
children.forEach { $0.beginAppearanceTransition(true, animated: animated) }
}
Expand Down Expand Up @@ -149,7 +153,11 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
}

open func moveToViewController(at index: Int, animated: Bool = true) {
guard isViewLoaded && view.window != nil && currentIndex != index else {
guard isViewLoaded && !viewControllers.isEmpty && view.window != nil else {
// currentIndex and preCurrentIndex are compared in viewDidAppear
// If they differ, animated moveToViewController is called.
// For pre-viewDidLoad setup, we need to make sure the indices are same.
currentIndex = index
preCurrentIndex = index
return
}
Expand Down Expand Up @@ -229,9 +237,11 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
}

open func updateContent() {
if lastSize.width != containerView.bounds.size.width {
guard lastSize.width == containerView.bounds.size.width else {
lastSize = containerView.bounds.size
// Settings contentOffset calls scrollViewDidScroll which calls updateContent again.
containerView.contentOffset = CGPoint(x: pageOffsetForChild(at: currentIndex), y: 0)
return
}
lastSize = containerView.bounds.size

Expand Down Expand Up @@ -392,5 +402,6 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
private var lastSize = CGSize(width: 0, height: 0)
internal var isViewRotating = false
internal var isViewAppearing = false
private var didCallViewWillAppearOnce = false

}