diff --git a/Sources/Pageboy/Utilities/PatchedPageViewController.swift b/Sources/Pageboy/Utilities/PatchedPageViewController.swift index 773d422..43795a2 100644 --- a/Sources/Pageboy/Utilities/PatchedPageViewController.swift +++ b/Sources/Pageboy/Utilities/PatchedPageViewController.swift @@ -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) }