Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the scroll view position while moving between states #587

Closed
fawzirifai opened this issue Apr 15, 2023 · 6 comments
Closed

Preserve the scroll view position while moving between states #587

fawzirifai opened this issue Apr 15, 2023 · 6 comments

Comments

@fawzirifai
Copy link

Description

In the Maps example, while changing the search panel states the scroll view moves to the top.

Expected behavior

The scroll view position should be preserved while changing states like in Apple Maps.

Actual behavior

While changing states the scroll view moves to the top.

Steps to reproduce

Move the Search panel to the full state, scroll to the bottom of the scroll view, then move the panel to the half state.

Code example that reproduces the issue
I am using the code in the Maps example.

How do you display panel(s)?
Added as a child view controller.

How many panels do you displays?
1

Environment

Library version
2.6.1

Installation method
I am using the example included in the library.

iOS version(s)
16.4.1

Xcode version
14.3

@scenee
Copy link
Owner

scenee commented Apr 16, 2023

Thanks for your report. I'm fixing this problem now.

@fawzirifai
Copy link
Author

what is the status of this, please? @scenee

@fawzirifai
Copy link
Author

This commit fixes the issue, why it is not merged with the main yet? @scenee
03bb3bf

@scenee
Copy link
Owner

scenee commented Aug 11, 2023

Oh no! I had forgotten to continue working on this branch. Thank you for reminding me.

Indeed, while that commit certainly resolves the issue, I was thinking I couldn't merge it alone because the library also needs to consider other cases.

I'll review the branch again and work towards merging it.

@fawzirifai
Copy link
Author

Thanks for your reply, I appreciate it.

scenee added a commit that referenced this issue Aug 14, 2023
Previously, the panel might not consistently keep its scroll content
offset when moving from its most expanded state to another.

Changes made in this commit:

* Removed the need for an offset reset when users manually move the
  panel outside of the tracking scroll view.
* Stopped the scroll offset reset of the `stopScrollDeceleration` flag
  in the  `panningEnd` method when the panel transitions from its most
  expanded state because there is no issue without the reset.
scenee added a commit that referenced this issue Aug 14, 2023
Previously, the panel might not consistently keep its scroll content
offset when moving from its most expanded state to another.

Changes made in this commit:

* Keep the content offset of tracking scroll view in the following cases.
  A panel is moved...
  1. Outside of the tracking scroll view.
  2. Inside of a navigation bar/toolbar over the tracking scroll view.

* Stopped the scroll offset reset of the `stopScrollDeceleration` flag
  in the  `panningEnd` method when the panel transitions from its most
  expanded state because there is no issue without the reset.
@scenee scenee closed this as completed Sep 2, 2023
@gunnarsson
Copy link

gunnarsson commented Sep 10, 2024

This fix broke a piece of code of mine. I wonder if anybody could help me adjust it to work well with more modern versions of FloatingPanel.

Here's what I want to achieve: If the user expands the panel to .full state and scrolls down to the bottom of the panel, and then drags the handle down to move it to .half state, the content should scroll to top. Otherwise the user has to expand the panel again, manually scroll to top, and then pull it down to .half again, which is tedious.

Here's what I used to do:

    func floatingPanelDidChangeState(_ fpc: FloatingPanelController) {
        // If the content is scrolled down, restore it to the top when the state of the panel
        // changes, to prevent an awkward state where you have to move the panel up to full
        // in order to be able to scroll the content up again
        if fpc.state == .tip || fpc.state == .half {
            DispatchQueue.main.async {
                fpc.trackedScrollView?.setContentOffset(CGPoint.zero, animated: fpc.state == .half)
            }
        }
    }

The new pinning of the scroll position immediately sets the content offset back to the original position. I can make it work by delaying the async call an arbitrary amount of time, but that feels very hacky. Given this new functionality, how can I achieve the behavior I'm after? Can I prevent the pinning, or make my contentOffset adjustment in a more suitable callback?

gunnarsson added a commit to gunnarsson/FloatingPanel that referenced this issue Sep 15, 2024
…ing state transitions

In scenee#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants