From 63d85d33cc1e37434e780f80e66f4359d3e17c79 Mon Sep 17 00:00:00 2001 From: Muhammad Umer Date: Wed, 21 Jun 2023 22:00:04 +0500 Subject: [PATCH] chore: handle user interaction when user swipes quickly in page view controller --- Source/CourseContentPageViewController.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/CourseContentPageViewController.swift b/Source/CourseContentPageViewController.swift index 57658d184..b982eb652 100644 --- a/Source/CourseContentPageViewController.swift +++ b/Source/CourseContentPageViewController.swift @@ -116,7 +116,8 @@ public class CourseContentPageViewController : UIPageViewController, UIPageViewC // Filed http://www.openradar.appspot.com/radar?id=6188034965897216 against Apple to better expose // this API. // Verified on iOS9 and iOS 8 - if let scrollView = (view.subviews.compactMap { return $0 as? UIScrollView }).first { + if let scrollView = view.subviews.compactMap({ return $0 as? UIScrollView }).first { + scrollView.delegate = self scrollView.delaysContentTouches = false } addObservers() @@ -515,6 +516,19 @@ public class CourseContentPageViewController : UIPageViewController, UIPageViewC } } +// There is a bug with UIPageViewController, if user tries to quickly scroll between controllers, +// the UIPageViewControllerDelegate is not being called appropriately, +// to handle this, listen to UISsrollViewDelegate and handle the user interaction. +extension CourseContentPageViewController: UIScrollViewDelegate { + public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { + updateTransitionState(is: false) + } + + public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { + updateTransitionState(is: false) + } +} + // MARK: Testing extension CourseContentPageViewController { public func t_blockIDForCurrentViewController() -> OEXStream {