fix(tasks): 节点详情弹层同样避开窗口控件带
锚定弹层顶部下限也是 8px,锚点靠近窗口顶部时整张卡片的头部会落进原生窗口 按钮带。改用同一份控件带几何:锚点自身在带内时也向下退让,拖拽纵向下限同步。
This commit is contained in:
1 parent
3939fe5b6e
commit
a95c65c09c
1 file changed
+11
-5
@@ -21,6 +21,7 @@ import {
|
||||
} from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { createFrameBatcher } from './frame-batcher.ts'
|
||||
import { useViewportInsetTop } from './viewport-inset.ts'
|
||||
|
||||
/** The popover's default visual width (viewport-clamped). */
|
||||
const POP_WIDTH = 264
|
||||
@@ -62,6 +63,8 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode {
|
||||
const baseRef = useRef({ left: 0, top: 0 })
|
||||
|
||||
const cardWidth = Math.min(width, window.innerWidth - VIEWPORT_MARGIN * 2)
|
||||
/** The shell's native window-control band: pointer events die in it. */
|
||||
const topFloor = VIEWPORT_MARGIN + useViewportInsetTop()
|
||||
|
||||
// Measure + position once the card is in the DOM (and whenever the anchor
|
||||
// or content changes size). layout effect: no visible jump.
|
||||
@@ -73,15 +76,18 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode {
|
||||
const height = card.offsetHeight
|
||||
let top = rect.bottom + 6
|
||||
if (top + height > window.innerHeight - VIEWPORT_MARGIN) {
|
||||
top = Math.max(VIEWPORT_MARGIN, rect.top - height - 6)
|
||||
top = Math.max(topFloor, rect.top - height - 6)
|
||||
}
|
||||
// The anchor itself may sit in the band (a row near the top edge): opening
|
||||
// just below it still leaves our own header under the native controls.
|
||||
top = Math.max(topFloor, top)
|
||||
const left = Math.min(
|
||||
Math.max(VIEWPORT_MARGIN, rect.left),
|
||||
Math.max(VIEWPORT_MARGIN, window.innerWidth - cardWidth - VIEWPORT_MARGIN),
|
||||
)
|
||||
baseRef.current = { left, top }
|
||||
setPos({ left: left + offsetRef.current.x, top: top + offsetRef.current.y })
|
||||
}, [anchor, children, cardWidth])
|
||||
}, [anchor, children, cardWidth, topFloor])
|
||||
|
||||
// A new anchor starts a fresh placement (never inherit another node's drag).
|
||||
useEffect(() => { setOffset({ x: 0, y: 0 }) }, [anchor])
|
||||
@@ -103,8 +109,8 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode {
|
||||
Math.max(VIEWPORT_MARGIN - base.left, window.innerWidth - cardWidth - VIEWPORT_MARGIN - base.left),
|
||||
)
|
||||
const nextY = Math.min(
|
||||
Math.max(start.y + (move.clientY - startY), VIEWPORT_MARGIN - base.top),
|
||||
Math.max(VIEWPORT_MARGIN - base.top, window.innerHeight - 48 - base.top),
|
||||
Math.max(start.y + (move.clientY - startY), topFloor - base.top),
|
||||
Math.max(topFloor - base.top, window.innerHeight - 48 - base.top),
|
||||
)
|
||||
pendingDragRef.current = {
|
||||
offset: { x: nextX, y: nextY },
|
||||
@@ -127,7 +133,7 @@ export function AnchoredPopover(props: AnchoredPopoverProps): ReactNode {
|
||||
window.addEventListener('pointermove', onMove)
|
||||
window.addEventListener('pointerup', onUp)
|
||||
window.addEventListener('pointercancel', onUp)
|
||||
}, [cardWidth, dragBatcher, draggable])
|
||||
}, [cardWidth, dragBatcher, draggable, topFloor])
|
||||
|
||||
// Global dismissal (see the file header for the contract).
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user