-
-
Notifications
You must be signed in to change notification settings - Fork 538
fix: Fix offset reset issue caused by floating-point precision at boundary positions #677
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
Conversation
…ndary positions When the panel is already at a boundary position, floating-point precision errors on some devices can cause unexpected offset resets in the position calculation. By applying floor() to the position calculations for top, left, bottom, and right edges in FloatingPanelLayoutAnchor, we ensure integer values are returned, preventing layout issues caused by floating-point precision errors.
8899093 to
7971502
Compare
|
The code implementation plan has been adjusted and fixed, and all local unit tests have passed. 2026-01-13.16.48.33_compressed.mp4 |
|
Hi, thank you so much for the patch and the sample project! The sample project is incredibly helpful for reproducing the issue. I definitely want to get this fixed. Regarding the current patch, I have one concern: while using I noticed you updated the patch to fix the unit tests, but your previous approach to Based on your contribution, I’m thinking of refining the fix as follows. What do you think? @@ -306,7 +306,7 @@ class LayoutAdapter {
}
func surfaceLocation(for state: FloatingPanelState) -> CGPoint {
- let pos = position(for: state).rounded(by: surfaceView.fp_displayScale)
+ let pos = position(for: state)
switch layout.position {
case .top, .bottom:
return CGPoint(x: 0.0, y: pos)
@@ -316,6 +316,10 @@ class LayoutAdapter {
}
func position(for state: FloatingPanelState) -> CGFloat {
+ return _position(for: state).rounded(by: surfaceView.fp_displayScale)
+ }
+
+ private func _position(for state: FloatingPanelState) -> CGFloat {
let bounds = vc.view.bounds
let anchor = layout.anchors[state] ?? self.hiddenAnchor
|
|
Because my projects all pop up from the bottom, I haven't noticed other directions. It would be great if you could provide a better solution. You can simply close this PR. I will update it as soon as you fix it. Thank you so much for developing this library. |
|
Thank you for your understanding and for the quick reply! Please don't feel like you need to close it just yet — your contribution has been invaluable. Thanks to your sample project and your initial insight into the floating-point error, I now have a very clear path to the fix. I will take it from here and apply a universal fix based on your findings. I’ll make sure to credit your contribution in the commit and release note. Thank you again for your support and for using the library! |
When the panel is already at a boundary position, floating-point precision errors on some devices (like iPhone 17 Pro Max) can cause unexpected offset resets in the position calculation. This commit addresses the layout issue where fractional values caused incorrect position evaluation. Based on the initial fix and sample project provided by @0x1306a94. Co-authored-by: 0x1306a94 <onyxes_accent_0a@icloud.com>
* Replace fatal errors in transitionDuration delegate methods (scenee#642) This PR modifies the transitionDuration(using:) method in FloatingPanelController to return 0.0 instead of calling fatalError when the FloatingPanelController instance is not found. This change is crucial for several reasons: 1. Avoiding Crashes in Production: Using fatalError in production can lead to unexpected crashes, which are detrimental to user experience. It's safer to return a default value like 0.0 and handle the scenario gracefully. 2. Improved Stability: By returning 0.0, the application can continue running, allowing for better stability and user satisfaction. This approach also aligns with the principle of fail-safety, where the system continues operating under error conditions. 3. Real-World Case: In our large-scale project, we encountered a crash at this specific point due to the fatalError. Given the size and complexity of our application, it has been challenging to pinpoint the exact cause. Switching to a return value of 0.0 would significantly help us mitigate the issue and maintain app stability while we investigate further. 4. Maintainability: Returning a default value makes the codebase more maintainable and easier to debug, as it avoids abrupt termination and allows for logging or other error handling mechanisms. * Version 2.8.5 * Fix doc comments' errors (scenee#644) * Fix doc comment errors in ObjC APIs * Improve doc comments in LayoutAnchoring.swift * Version 2.8.6 * Disallow interrupting the panel interaction while bouncing over the most expanded state (scenee#652) I decided to disallow interrupting panel interactions while bouncing over the most expanded state in order to fix the 2nd issue in scenee#633, scenee#633 (comment). * Reset `initialScrollOffset` after the attracting animation ends (scenee#659) * Stop pinning the scroll offset in moving programmatically * Add 'optional' string interpolation * Add comments * Add CoreTests.test_initial_scroll_offset_reset() * ci: remove macos-12 jobs for the deprecation * ci: name circleci jobs * ci: use Xcode 16.2 (scenee#653) * Added '--verbose' in cocoapods job * Fixed 'error: No simulator runtime version'. Some of the example apps cannot be built on github actions. > /Users/runner/work/FloatingPanel/FloatingPanel/Examples/Samples/Sources/Assets.xcassets: error: No simulator runtime version from [<DVTBuildVersion 21A342>, <DVTBuildVersion 21C62>, <DVTBuildVersion 21E213>, <DVTBuildVersion 21F79>, <DVTBuildVersion 22B81>] available to use with iphonesimulator SDK version <DVTBuildVersion 22C146> * Used macos-15 to fix random build fails * ci: use macos-15 for all testing to use Xcode 16.2 * Version 2.8.7 * Revert "Disallow interrupting the panel interaction while bouncing over the most expanded state (scenee#652)" This reverts commit b0fd0d4. This change had a problem normal cases. For example, in Maps example a panel interaction jumps occurs because of this. * Allow slight deviation when checking for anchor position. This change addresses the 2nd issue reported in scenee#633. The previous attempt in commit b0fd0d4 was intended to fix this, but it has a regression. This change resolves the issue without introducing any regressions. * Fix a miss spell * Address scenee#661 issue since v2.8.0 (scenee#662) See this comment for more details. scenee#661 (comment) * Version 2.8.8 * ci: add workflow_dispatch event trigger * Update FloatingPanelController * Dump the default config of swift-format on Xcode 16.3 * Lint the library code by built-in swift-format * Ignore project.xcworkspace dir * Update .swift-format * Update the minimum deployment target to iOS 13 * Drop Xcode 13.4.1 support The following errors occur only on Xcode 13.4.1. Addressing them would significantly impair the usability of this library’s API. Therefore, I have decided not to support Xcode 13.4.1. > /.../FloatingPanel/Sources/SwiftUI/FloatingPanelView.swift:9:33: error: protocol 'FloatingPanelCoordinator' can only be used as a generic constraint because it has Self or associated type requirements > let coordinator: () -> (any FloatingPanelCoordinator) > ^ > /.../FloatingPanel/Sources/SwiftUI/FloatingPanelView.swift:78:42: error: protocol 'FloatingPanelCoordinator' can only be used as a generic constraint because it has Self or associated type requirements > public func makeCoordinator() -> any FloatingPanelCoordinator { > ^ > /.../FloatingPanel/Sources/SwiftUI/View+floatingPanel.swift:26:67: error: 'some' types are only implemented for the declared type of properties and subscripts and the return type of functions > @ViewBuilder _ content: @escaping (FloatingPanelProxy) -> some View > ^ > /.../FloatingPanel/Sources/SwiftUI/View+floatingPanel.swift:26:9: error: result builder attribute 'ViewBuilder' can only be applied to a parameter of function type > @ViewBuilder _ content: @escaping (FloatingPanelProxy) -> some View > ^ > /.../FloatingPanel/Sources/SwiftUI/View+floatingPanel.swift:24:31: error: default argument value of type 'FloatingPanelDefaultCoordinator.Type' cannot be converted to type 'T.Type' > coordinator: T.Type = FloatingPanelDefaultCoordinator.self, > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > as! T.Type > /.../FloatingPanel/Sources/SwiftUI/View+floatingPanel.swift:28:9: error: generic parameter 'ContentView' could not be inferred > FloatingPanelView( > ^ > /.../FloatingPanel/Sources/SwiftUI/FloatingPanelView.swift:8:49: note: 'ContentView' declared as parameter to type 'FloatingPanelView' > public struct FloatingPanelView<MainView: View, ContentView: View>: UIViewControllerRepresentable { > ^ > /.../FloatingPanel/Sources/SwiftUI/View+floatingPanel.swift:28:9: note: explicitly specify the generic arguments to fix this issue > FloatingPanelView( > ^ > <Self, <#ContentView: View#>> * Expand timeout for some test cases in {Controller,Core}Tests * Implement SwiftUI APIs based on the Maps-SwiftUI app * Added SamplesSwiftUI * Moved Maps-SwiftUI project in workspace * Updated build tools * Fixed xcode 15.1 build * Added FloatingPanel.SurfaceAppearance.box() * Polish source code of CoreTests a bit * Take care of file paths including non-ASCII chars in SwiftFormatBuildToolPlugin * Add .xcodesamplecode.plist * Move 'assets' folder in 'Documentation' folder * Update documentation for the new SwiftUI APIs * Added 'FloatingPanel SwiftUI API Guide' * Updated README * ci: update example builds * ci: fix swift 5.9 and 5.10 builds * ci: use Xcode 16.3 and iOS 18.4 * Add CHANGELOG * Version 3.0.0 * Modify the top page of the DocC * Improve CoreTests a bit * ci: fix the build environments * Fix the pod spec for the SwiftUI APIs * Version 3.0.1 * ci: remove builds using deprecated 'macos-13' machine * Add support for UICornerConfiguration in iOS 26 (scenee#664) * ci: add iOS 26 to test matrix * Pass CoreTests.test_initial_scroll_offset_reset() Since iOS 26, UIGestureRecognizer.state is not able to change even if it's assigned a new value programmatically. Therefore, I created MockPanGestureRecognizer to change the state property in testing. * Fix a build error on Xcode 16 * Fix compilation conditions at c5291d7 * Enable to build it for iOS 12 * Add CoreTests.test_statePublisher * ci: fix a job error * Add 'Star History Chart' at the bottom of README * Set minimum iOS version to v12 * Version 3.1.0 * Support dynamic content updates in SwiftUI Store content hosting controller reference and update it dynamically in updateUIViewController(), allowing panel content to change without recreation. Resolved scenee#672 * Improve SamplesSwiftUI * ci: use Xcode 26.0.1 for all builds * Fix shadow on iOS 26 * examples: fix animation glitch on iOS 26 * Version 3.2.0 * Remove badges from README * ci: fix 'swiftpm' job * Fix scroll offset reset due to floating-point precision errors (scenee#677) When the panel is already at a boundary position, floating-point precision errors on some devices (like iPhone 17 Pro Max) can cause unexpected offset resets in the position calculation. This commit addresses the layout issue where fractional values caused incorrect position evaluation. Based on the initial fix and sample project provided by @0x1306a94. Co-authored-by: 0x1306a94 <onyxes_accent_0a@icloud.com> * Perform view updates during scroll tracking (scenee#679) When we enable floatingPanelScrollTracking on our view inside of the floating panel, some view updates are performed (i.e., SwiftUI views are being instantiated) but no rendering (i.e., body evaluations) occurs. Example code: ```swift content .floatingPanel( coordinator: ContentPanelCoordinator.self, onEvent: onEvent ) { proxy in panelContent .floatingPanelScrollTracking(proxy: proxy) // scroll tracking breaks view updates } ``` We tracked this down to the scroll tracking, and it seems that the performing of view updates inside of the ScrollViewRepresentable was missing. This seems similar to scenee#675. * Version 3.2.1 --------- Co-authored-by: Ivan Levin <100189059+LevinIvan@users.noreply.github.com> Co-authored-by: Shin Yamamoto <shin@scenee.com> Co-authored-by: Will Bishop <17292672+WillBishop@users.noreply.github.com> Co-authored-by: 0x1306a94 <onyxes_accent_0a@icloud.com> Co-authored-by: Sören Gade <gade.soeren@gmail.com>
When the panel is already at a boundary position, floating-point precision errors on some devices can cause unexpected offset resets in the position calculation.
By applying floor() to the position calculations for top, left, bottom, and right edges in FloatingPanelLayoutAnchor, we ensure integer values are returned, preventing layout issues caused by floating-point precision errors.
#626
FloatingPanelSample.zip
2026-01-13.09.56.34_compressed.mp4