From 62355919a38c7e154947424d732d560612c26f64 Mon Sep 17 00:00:00 2001 From: Muhammad Umer Date: Fri, 23 Jun 2023 17:21:31 +0500 Subject: [PATCH] chore: handle user interaction when user swipes quickly in page view controller (#1766) --- 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 {