#BUG# `initialScrollOffset` causes incorrect scrollView behavior since version `2.8.0`
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
- Scroll the scrollView to the middle.
- Reset the scrollView’s contentOffset to .zero.
- 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
Thank you for your feedback. I'm trying to fix this issue on iss-658 branch.
Hi @MrPans, I believe #659 resolves this issue. Could you please double-check whether this bug is addressed in the pull request? Thank you!
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
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.
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.
I've merged #659 and then this was closed unexpectedly. So I reopened this. I would like to keep track of this issue.