FloatingPanel
FloatingPanel copied to clipboard
Enabling scrollView scrolling up while not at top state
Thanks for the work, it has been a great help so far !
Description
What I want to achieve is
- To have a .full and .half floating panel,
- Inside the floating panel is a tableView (or any scroll view, does not matter)
- When the panel is in .half mode, if the content offset > 0, I wish to be able to scroll up the list, without moving the floating panel
Expected behavior
- To be able to scroll up the list while in .half mode
Actual behavior
- The panel goes down (or to .tip, depending on the configuration)
Steps to reproduce
In the sample app, it's possible to simulate the use case by the following : -Scroll tracking (tableview) -Scroll down the list (so the panel goes to .full) -Move using the grab handle to .half ---> Move your finger up inside the table to scroll up the list while in .half mode ---> The panel goes to down instead
Code example that reproduces the issue
I've looked around in the code, and from what I see the behavior is coming from Core.swift
, line about 384
if state == layoutAdapter.edgeMostState, self.transitionAnimator == nil {
switch layoutAdapter.position {
case .top, .left:
if offsetDiff < 0 && velocity > 0 {
unlockScrollView()
}
case .bottom, .right:
if offsetDiff > 0 && velocity < 0 {
unlockScrollView()
}
}
}
I wish to unlock the Scroll view, but the state == layoutAdapter.edgeMostState
is false
. It's probably more complex that this, but the desired effect is here.
What I tried I try to implement the delegate in the following way
func floatingPanelShouldBeginDragging(_ vc: FloatingPanelController) -> Bool {
return (vc.trackingScrollView?.contentOffset.y ?? 0) <= 0
}
A bit naively, but it did not work. I just want the scrolling of the scrollview to be prioritized over the pan gesture if going swiping finger down, scrollView.contentOffset.y > 0 and floating panel not at the top state.
How do you display panel(s)?
- Add as child view controllers
How many panels do you displays?
- 2+
Environment
Library version 2.3.0
Installation method
- CocoaPods
iOS version(s) 14.4
Xcode version 12.4
Thank you for your feature request and detail description about it. I will consider this feature. I think this library might need a new API for it, a delegate method or something.
I created iss-455
branch for this use case. Instead of adding a new delegate method, I fixed the scroll tracking feature a bit. In this branch, you're able to turn on/off the scroll tracking in any states as expected. I hope this change would be sufficient for this use case.
Thanks. I've tried the branch iss-455
and it does not fix the use case. Not out of the box. I would like to leave the tracking "on" and I see that with this branch, to get the behavior I want, I need to "untrack" the scroll view.
From what I understand, with this branch, I would need to untrack the scroll view when the floating panel moves to .half. Then, when the user is scrolling the tableview and get close to the end/start (using will display cell delegate) track again the scroll view (so that it can move to .tip or .full)
But this seems a bit too much tracking/untracking to do, and could lead to error.
Thank you for your feedback. I understood track/untrack APIs are not enough for the use case. I'll try to reconsider the API design.
Hi @scenee, I've checked branch iss-455
In the .tip state I was able to scroll up to see the first row of the tableView.
But one case: I am not able to move from .tip to .full state what I was doing before. It looks like a bug.
I think need to allow scroll in one direction for the smallestState to see first row of the tableView and save previous behaviour.
@KirylBelasheuski I'm sorry for my late reply. Thank you for your feedback. I will check the case.
@scenee hi! any updates here?
I've finally added the new delegate method, floatingPanel(_:shouldAllowToScroll) -> Bool
in the main branch. It allows the library user to determine whether the content scrolls or not in certain state.
Here is an example behavior in the Maps example app.
https://github.com/scenee/FloatingPanel/assets/899487/d1d06dee-ff88-4641-b766-0f879424c499
This example app implements the new delegate method like this.
func floatingPanel(_ fpc: FloatingPanelController, shouldAllowToScroll trackingScrollView: UIScrollView) -> Bool {
return fpc.state == .full || fpc.state == .half
}