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

#BUG# initialScrollOffset causes incorrect scrollView behavior since version 2.8.0 #658

Open
MrPans opened this issue Jan 15, 2025 · 5 comments · May be fixed by #659
Open

#BUG# initialScrollOffset causes incorrect scrollView behavior since version 2.8.0 #658

MrPans opened this issue Jan 15, 2025 · 5 comments · May be fixed by #659

Comments

@MrPans
Copy link

MrPans commented Jan 15, 2025

Description

Since version 2.8.0, the Core records the initialScrollOffset in the panningBegan(at:) method. However, panningBegan(at:) is only called when the user scrolls the scrollView manually, not when setContentOffset is used programmatically. This causes an issue when developers try to reset the scrollView using setContentOffset while changing the floating panel state from .full to .half. The floating panel incorrectly uses the previously recorded initialScrollOffset to set the scrollView’s contentOffset, which is not the expected behavior.

Expected behavior

The Core should correctly record the contentOffset of the scrollView when setContentOffset is called programmatically.

Actual behavior

The Core only updates based on pan gesture changes and does not handle programmatic changes to the contentOffset.

Steps to reproduce

  1. Scroll the scrollView to the middle.
  2. Reset the scrollView’s contentOffset to .zero.
  3. Change the floating panel state to .half.

Code example that reproduces the issue

    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
        resetSearchBar()
        panelController?.move(to: .half, animated: true, completion: nil)
        scrollView?.scrollRectToVisible(CGRect(x: 0, y: 0, width: 100, height: 10), animated: true)
    }

How do you display panel(s)?

  • Add as child view controllers

How many panels do you displays?

  • 1

Environment

Library version
latest

Installation method

  • CocoaPods

iOS version(s)
iOS 18

Xcode version
16.0

@MrPans MrPans changed the title initialScrollOffset made a error scrollview content since 2.8.0 #BUG initialScrollOffset made a error scrollview content since 2.8.0 Jan 15, 2025
@MrPans MrPans changed the title #BUG initialScrollOffset made a error scrollview content since 2.8.0 #BUG# initialScrollOffset made a error scrollview content since 2.8.0 Jan 15, 2025
@MrPans MrPans changed the title #BUG# initialScrollOffset made a error scrollview content since 2.8.0 #BUG# initialScrollOffset causes **incorrect scrollView behavior** since version 2.8.0 Jan 15, 2025
@MrPans MrPans changed the title #BUG# initialScrollOffset causes **incorrect scrollView behavior** since version 2.8.0 #BUG# initialScrollOffset causes *incorrect scrollView behavior* since version 2.8.0 Jan 15, 2025
@MrPans MrPans changed the title #BUG# initialScrollOffset causes *incorrect scrollView behavior* since version 2.8.0 #BUG# initialScrollOffset causes incorrect scrollView behavior since version 2.8.0 Jan 15, 2025
@scenee
Copy link
Owner

scenee commented Jan 28, 2025

Thank you for your feedback. I'm trying to fix this issue on iss-658 branch.

@scenee
Copy link
Owner

scenee commented Jan 29, 2025

Hi @MrPans, I believe #659 resolves this issue. Could you please double-check whether this bug is addressed in the pull request? Thank you!

@MrPans
Copy link
Author

MrPans commented Jan 29, 2025

Hi @scenee, thanks for your work and quick response. I tested the iss-658 branch as a local pod, but unfortunately, it doesn’t seem to fix the issue. Below is the screen recording for reference.
https://github.com/user-attachments/assets/6d37db52-0aee-496e-bee8-ad747d5cd997

@scenee
Copy link
Owner

scenee commented Feb 1, 2025

I thought this problem could be reproduced this issue with the following patch for the Samples app.

diff --git a/Examples/Samples/Sources/ContentViewControllers/ModalViewController.swift b/Examples/Samples/Sources/ContentViewControllers/ModalViewController.swift
index 6a870fe..5d15ac1 100644
--- a/Examples/Samples/Sources/ContentViewControllers/ModalViewController.swift
+++ b/Examples/Samples/Sources/ContentViewControllers/ModalViewController.swift
@@ -46,6 +46,7 @@ final class ModalViewController: UIViewController, FloatingPanelControllerDelega
     }
     @IBAction func moveToHalf(sender: UIButton) {
         fpc.move(to: .half, animated: true)
+        consoleVC.textView.scrollRectToVisible(CGRect(x: 0, y: 55, width: 100, height: 100), animated: true)
     }
     @IBAction func moveToTip(sender: UIButton) {
         fpc.move(to: .tip, animated: true)
diff --git a/FloatingPanel.xcodeproj/project.pbxproj b/FloatingPanel.xcodeproj/project.pbxproj

scrollRectToVisible is working expectedly on iss-658 branch, not on the master branch. So I supposed your problem was resolved. However my reproduction seems to miss something, so It's helpful that you give me more information to reproduce your condition.

@MrPans
Copy link
Author

MrPans commented Feb 1, 2025

Hi @scenee,

I made an independent TableView demo, and it works fine with the iss-658 branch but not on the master branch. However, when I use the iss-658 branch in my project, the issue still persists. My project uses UICollectionViewCompositionalLayout, which might be related.

Once I finish my current tasks, I’ll try to extract a minimal demo with CompositionalLayout to reproduce the issue.

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

Successfully merging a pull request may close this issue.

2 participants