Skip to content

Commit 7971502

Browse files
committed
fix: Fix offset reset issue caused by floating-point precision at boundary 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.
1 parent 9e8fd34 commit 7971502

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Sources/Core.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {
432432
let velocity = value(of: panGesture.velocity(in: panGesture.view))
433433
let location = panGesture.location(in: surfaceView)
434434

435-
let insideMostExpandedAnchor = 0 < layoutAdapter.offsetFromMostExpandedAnchor
435+
let insideMostExpandedAnchor = 0 < floor(layoutAdapter.offsetFromMostExpandedAnchor)
436436

437437
os_log(msg, log: devLog, type: .debug, """
438438
scroll gesture(\(state):\(panGesture.state)) -- \
@@ -927,7 +927,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {
927927
}
928928

929929
private func shouldAttract(to state: FloatingPanelState) -> Bool {
930-
if layoutAdapter.position(for: state) == value(of: layoutAdapter.surfaceLocation) {
930+
if floor(layoutAdapter.position(for: state)) == floor(value(of: layoutAdapter.surfaceLocation)) {
931931
return false
932932
}
933933
return true

0 commit comments

Comments
 (0)