From a95c65c09c54f1edc5909ca878faecd4106b4892 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 4 Nov 2026 22:09:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(tasks):=20=E8=8A=82=E7=82=B9=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=BC=B9=E5=B1=82=E5=90=8C=E6=A0=B7=E9=81=BF=E5=BC=80?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=8E=A7=E4=BB=B6=E5=B8=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 锚定弹层顶部下限也是 8px,锚点靠近窗口顶部时整张卡片的头部会落进原生窗口 按钮带。改用同一份控件带几何:锚点自身在带内时也向下退让,拖拽纵向下限同步。 --- src/client/AnchoredPopover.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/client/AnchoredPopover.tsx b/src/client/AnchoredPopover.tsx index f45ec389..914d1d60 100644 --- a/src/client/AnchoredPopover.tsx +++ b/src/client/AnchoredPopover.tsx @@ -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(() => {