feat: snap floating add button to edge
This commit is contained in:
@@ -170,6 +170,14 @@ export function clampFabPosition(x: number, y: number, viewportWidth: number, vi
|
||||
}
|
||||
}
|
||||
|
||||
export function snapFabPosition(x: number, y: number, viewportWidth: number, viewportHeight: number, size = 52, margin = 14, bottomReserved = 74) {
|
||||
const clamped = clampFabPosition(x, y, viewportWidth, viewportHeight, size, margin, bottomReserved)
|
||||
const left = margin
|
||||
const right = Math.max(margin, viewportWidth - size - margin)
|
||||
const midpoint = viewportWidth / 2
|
||||
return { x: clamped.x + size / 2 < midpoint ? left : right, y: clamped.y }
|
||||
}
|
||||
|
||||
export function isFabDrag(deltaX: number, deltaY: number, threshold = 8) {
|
||||
return Math.hypot(deltaX, deltaY) >= threshold
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user