diff --git a/Sources/Pageboy.xcodeproj/project.pbxproj b/Sources/Pageboy.xcodeproj/project.pbxproj index 005aef14..378435f2 100755 --- a/Sources/Pageboy.xcodeproj/project.pbxproj +++ b/Sources/Pageboy.xcodeproj/project.pbxproj @@ -9,8 +9,8 @@ /* Begin PBXBuildFile section */ 460906B7222A785E005474BF /* WeakContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 460906B6222A785E005474BF /* WeakContainer.swift */; }; 460906B9222A79F6005474BF /* IndexedObjectMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 460906B8222A79F6005474BF /* IndexedObjectMap.swift */; }; - 461D6DF1201795A100E0CDEE /* UIScrollView+ScrollActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461D6DF0201795A100E0CDEE /* UIScrollView+ScrollActivity.swift */; }; - 461D6DF2201795A100E0CDEE /* UIScrollView+ScrollActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461D6DF0201795A100E0CDEE /* UIScrollView+ScrollActivity.swift */; }; + 461D6DF1201795A100E0CDEE /* UIScrollView+Interaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461D6DF0201795A100E0CDEE /* UIScrollView+Interaction.swift */; }; + 461D6DF2201795A100E0CDEE /* UIScrollView+Interaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461D6DF0201795A100E0CDEE /* UIScrollView+Interaction.swift */; }; 462A65DD2000FCAA0051C79C /* UIView+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 462A65D92000FCAA0051C79C /* UIView+Localization.swift */; }; 462A65DE2000FCAA0051C79C /* UIView+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 462A65D92000FCAA0051C79C /* UIView+Localization.swift */; }; 462A65DF2000FCAA0051C79C /* UIView+AutoLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 462A65DA2000FCAA0051C79C /* UIView+AutoLayout.swift */; }; @@ -85,7 +85,7 @@ /* Begin PBXFileReference section */ 460906B6222A785E005474BF /* WeakContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakContainer.swift; sourceTree = ""; }; 460906B8222A79F6005474BF /* IndexedObjectMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexedObjectMap.swift; sourceTree = ""; }; - 461D6DF0201795A100E0CDEE /* UIScrollView+ScrollActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIScrollView+ScrollActivity.swift"; sourceTree = ""; }; + 461D6DF0201795A100E0CDEE /* UIScrollView+Interaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIScrollView+Interaction.swift"; sourceTree = ""; }; 462A65D92000FCAA0051C79C /* UIView+Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Localization.swift"; sourceTree = ""; }; 462A65DA2000FCAA0051C79C /* UIView+AutoLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+AutoLayout.swift"; sourceTree = ""; }; 462A65DB2000FCAA0051C79C /* UIApplication+SafeShared.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+SafeShared.swift"; sourceTree = ""; }; @@ -160,7 +160,7 @@ 462A65DA2000FCAA0051C79C /* UIView+AutoLayout.swift */, 462A65DB2000FCAA0051C79C /* UIApplication+SafeShared.swift */, 462A65DC2000FCAA0051C79C /* UIPageViewController+ScrollView.swift */, - 461D6DF0201795A100E0CDEE /* UIScrollView+ScrollActivity.swift */, + 461D6DF0201795A100E0CDEE /* UIScrollView+Interaction.swift */, 462D03DE2091D3AB0033C710 /* UIView+Animation.swift */, BB5277382211308B003695BB /* DispatchQueue+main.swift */, ); @@ -502,7 +502,7 @@ 462A65E32000FCAA0051C79C /* UIPageViewController+ScrollView.swift in Sources */, 460906B9222A79F6005474BF /* IndexedObjectMap.swift in Sources */, 46ADAAC2208F7E8500974529 /* TransitionOperation.swift in Sources */, - 461D6DF1201795A100E0CDEE /* UIScrollView+ScrollActivity.swift in Sources */, + 461D6DF1201795A100E0CDEE /* UIScrollView+Interaction.swift in Sources */, 462A65DF2000FCAA0051C79C /* UIView+AutoLayout.swift in Sources */, 46ADAAC8208F7EB200974529 /* PageboyViewController+Updating.swift in Sources */, BB5277392211308B003695BB /* DispatchQueue+main.swift in Sources */, @@ -550,7 +550,7 @@ 464ADF562097565D00929AFB /* Page.swift in Sources */, 46ADAAB9208F7E1500974529 /* PageboyViewController+AutoScrolling.swift in Sources */, 462A65E42000FCAA0051C79C /* UIPageViewController+ScrollView.swift in Sources */, - 461D6DF2201795A100E0CDEE /* UIScrollView+ScrollActivity.swift in Sources */, + 461D6DF2201795A100E0CDEE /* UIScrollView+Interaction.swift in Sources */, 46ADAAC3208F7E8500974529 /* TransitionOperation.swift in Sources */, 462A65E02000FCAA0051C79C /* UIView+AutoLayout.swift in Sources */, 46ADAAC9208F7EB200974529 /* PageboyViewController+Updating.swift in Sources */, diff --git a/Sources/Pageboy/PageboyViewController+Updating.swift b/Sources/Pageboy/PageboyViewController+Updating.swift index a5d69be1..d7b91353 100644 --- a/Sources/Pageboy/PageboyViewController+Updating.swift +++ b/Sources/Pageboy/PageboyViewController+Updating.swift @@ -33,13 +33,14 @@ internal extension PageboyViewController { func performUpdates(for newIndex: PageIndex?, viewController: UIViewController?, update: (operation: UpdateOperation, behavior: PageUpdateBehavior), - indexOperation: (_ currentIndex: PageIndex, _ newIndex: PageIndex) -> Void) { + indexOperation: (_ currentIndex: PageIndex, _ newIndex: PageIndex) -> Void, + completion: ((Bool) -> Void)?) { guard let newIndex = newIndex, let viewController = viewController else { // no view controller - reset updateViewControllers(to: [UIViewController()], animated: false, async: false, force: false, - completion: nil) + completion: completion) self.currentIndex = nil return } @@ -49,7 +50,7 @@ internal extension PageboyViewController { animated: false, async: false, force: false, - completion: nil) + completion: completion) self.currentIndex = newIndex return } @@ -64,7 +65,7 @@ internal extension PageboyViewController { animated: false, async: true, force: false, - completion: nil) + completion: completion) }) } else { // update is happening on some other page. indexOperation(currentIndex, newIndex) @@ -72,6 +73,7 @@ internal extension PageboyViewController { // If we are deleting, check if the new index is greater than the current. If it is then we // dont need to do anything... if update.operation == .delete && newIndex > currentIndex { + completion?(true) return } @@ -83,6 +85,7 @@ internal extension PageboyViewController { case .insert: guard let currentViewController = currentViewController else { + completion?(true) return } newViewController = currentViewController @@ -93,9 +96,11 @@ internal extension PageboyViewController { updateViewControllers(to: [newViewController], animated: false, async: true, force: false, completion: { [weak self, newIndex, update] _ in self?.performScrollUpdate(to: newIndex, behavior: update.behavior) + completion?(true) }) } else { // Otherwise just perform scroll update performScrollUpdate(to: newIndex, behavior: update.behavior) + completion?(true) } } } diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index 3e38db6b..664565f3 100755 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -288,15 +288,17 @@ open class PageboyViewController: UIViewController { viewControllerCount = newPageCount viewControllerIndexMap.removeAll() - - performUpdates(for: index, - viewController: newViewController, - update: (operation: .insert, behavior: updateBehavior), - indexOperation: { (index, newIndex) in - + + pageViewController?.scrollView?.cancelTouches() + view.isUserInteractionEnabled = false + performUpdates(for: index, viewController: newViewController, + update: (operation: .insert, behavior: updateBehavior), + indexOperation: { (index, newIndex) in if index >= newIndex { currentIndex = index + 1 - } + }}, + completion: { (_) in + self.view.isUserInteractionEnabled = true }) }) } @@ -329,14 +331,16 @@ open class PageboyViewController: UIViewController { viewControllerCount = newPageCount viewControllerIndexMap.removeAll() - performUpdates(for: newIndex, - viewController: newViewController, + pageViewController?.scrollView?.cancelTouches() + view.isUserInteractionEnabled = false + performUpdates(for: newIndex, viewController: newViewController, update: (operation: .delete, behavior: updateBehavior), indexOperation: { (index, newIndex) in - if index > newIndex { currentIndex = index - 1 - } + }}, + completion: { (_) in + self.view.isUserInteractionEnabled = true }) }) } diff --git a/Sources/Pageboy/Utilities/Extensions/UIScrollView+ScrollActivity.swift b/Sources/Pageboy/Utilities/Extensions/UIScrollView+Interaction.swift similarity index 67% rename from Sources/Pageboy/Utilities/Extensions/UIScrollView+ScrollActivity.swift rename to Sources/Pageboy/Utilities/Extensions/UIScrollView+Interaction.swift index 2938a468..52c6e61e 100644 --- a/Sources/Pageboy/Utilities/Extensions/UIScrollView+ScrollActivity.swift +++ b/Sources/Pageboy/Utilities/Extensions/UIScrollView+Interaction.swift @@ -1,5 +1,5 @@ // -// UIScrollView+ScrollActivity.swift +// UIScrollView+Interaction.swift // Pageboy // // Created by Merrick Sapsford on 23/01/2018. @@ -14,4 +14,9 @@ internal extension UIScrollView { var isProbablyActiveInScroll: Bool { return isTracking || isDecelerating } + + func cancelTouches() { + panGestureRecognizer.isEnabled = false + panGestureRecognizer.isEnabled = true + } }