From 13cf920af4f97e548faef2170548e653a8c68e4f Mon Sep 17 00:00:00 2001 From: Martin Gunnarsson Date: Sun, 15 Sep 2024 07:48:42 +0200 Subject: [PATCH] Allow delegate to decide whether the scroll view should be locked during state transitions In #587 the behavior of the panel was changed so that the content of the tracked scroll view is always locked during state transitions. In some cases it's useful to be able to adjust the scroll offset during these transitions, so a delegate method has been introduced letting the user of the library decide on this behavior. --- Sources/Controller.swift | 4 ++++ Sources/Core.swift | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/Controller.swift b/Sources/Controller.swift index ca29df14..0296dc75 100644 --- a/Sources/Controller.swift +++ b/Sources/Controller.swift @@ -125,6 +125,10 @@ import os.log shouldAllowToScroll scrollView: UIScrollView, in state: FloatingPanelState ) -> Bool + + /// Determines whether the scroll content should be locked during transition to the specified state. If not implemented, the content will always be locked. + @objc(floatingPanel:shouldLockScrollView:transitioningToState:) + optional func floatingPanel(_ fpc: FloatingPanelController, shouldLockScrollView scrollView: UIScrollView, transitioningToState state: FloatingPanelState) -> Bool } /// diff --git a/Sources/Core.swift b/Sources/Core.swift index 9188a7d2..5e45b086 100644 --- a/Sources/Core.swift +++ b/Sources/Core.swift @@ -933,8 +933,8 @@ class Core: NSObject, UIGestureRecognizerDelegate { let translation = data.value - initialData.value self.backdropView.alpha = self.getBackdropAlpha(at: current, with: translation) - // Pin the offset of the tracking scroll view while moving by this animator - if let scrollView = self.scrollView { + // Pin the offset of the tracking scroll view while moving by this animator, unless the delegate decides otherwise + if let scrollView = self.scrollView, ownerVC.delegate?.floatingPanel?(ownerVC, shouldLockScrollView: scrollView, transitioningToState: state) ?? true { self.stopScrolling(at: self.initialScrollOffset) os_log(msg, log: devLog, type: .debug, "move -- pinning scroll offset = \(scrollView.contentOffset)") }