Skip to content

Commit

Permalink
Update isAnimating to isSettingViewControllers
Browse files Browse the repository at this point in the history
Now evaluated universally regardless of animation
  • Loading branch information
msaps committed Nov 7, 2022
1 parent f7a24be commit 06a4150
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/Pageboy/Utilities/PatchedPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ import UIKit
/// Fixes not updating dataSource on animated setViewControllers. See: https://stackoverflow.com/a/13253884/715593
internal class PatchedPageViewController: UIPageViewController {

private var isAnimating = false
private var isSettingViewControllers = false

override func setViewControllers(_ viewControllers: [UIViewController]?, direction: UIPageViewController.NavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil) {
guard !isAnimating else {
guard !isSettingViewControllers else {
completion?(false)
return
}
isAnimating = animated
isSettingViewControllers = true
super.setViewControllers(viewControllers, direction: direction, animated: animated) { (isFinished) in
if isFinished && animated {
DispatchQueue.main.async {
super.setViewControllers(viewControllers, direction: direction, animated: false, completion: { _ in
self.isAnimating = false
self.isSettingViewControllers = false
})
}
} else {
self.isSettingViewControllers = false
}
completion?(isFinished)
}
Expand Down

0 comments on commit 06a4150

Please sign in to comment.