Skip to content

Commit

Permalink
Allow delegate to decide whether the scroll view should be locked dur…
Browse files Browse the repository at this point in the history
…ing 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.
  • Loading branch information
gunnarsson committed Sep 15, 2024
1 parent b6e8928 commit 13cf920
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Sources/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

///
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down

0 comments on commit 13cf920

Please sign in to comment.