From 06a415023a0df5985aa8d72ede4830a8b0e3ff63 Mon Sep 17 00:00:00 2001 From: msaps Date: Mon, 7 Nov 2022 18:20:38 +0100 Subject: [PATCH] Update isAnimating to isSettingViewControllers Now evaluated universally regardless of animation --- .../Pageboy/Utilities/PatchedPageViewController.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) }