feat(V0.2): 拖动跟手浮层 —— 半透明副本随指针, 原位虚线占位
Docker Build and Push / build-image (push) Successful in 1m5s
Docker Build and Push / build-image (push) Successful in 1m5s
- useRowDrag/useHabitDrag 暴露 ghostRef, 拖动激活与移动时直接改 transform (绕过 React 重渲染, 保证跟手流畅) - 打卡浮层带颜色点 + 名称; 任务列表浮层带任务名 + 实时目标列名 - 原位卡片降为低透明度虚线占位, 落点指示不变
This commit is contained in:
@@ -24,6 +24,13 @@ export default function useHabitDrag({ onDrop }) {
|
||||
const onDropRef = useRef(onDrop)
|
||||
onDropRef.current = onDrop
|
||||
|
||||
// 跟手浮层: 消费方渲染 <div ref={ghostRef}>, 拖动时 hook 直接改
|
||||
// transform (绕过 React 重渲染, 保证跟手流畅)
|
||||
const ghostRef = useRef(null)
|
||||
const moveGhost = (x, y) => {
|
||||
if (ghostRef.current) ghostRef.current.style.transform = `translate(${x}px, ${y}px) translate(-50%, -110%)`
|
||||
}
|
||||
|
||||
const cleanup = useCallback(() => {
|
||||
if (st.current.timer) { clearTimeout(st.current.timer); st.current.timer = null }
|
||||
st.current.active = false
|
||||
@@ -58,6 +65,7 @@ export default function useHabitDrag({ onDrop }) {
|
||||
return
|
||||
}
|
||||
ev.preventDefault()
|
||||
moveGhost(ev.clientX, ev.clientY)
|
||||
const hit = hitRow(ev.clientX, ev.clientY)
|
||||
if (hit) { s.over = hit; setOver(hit) }
|
||||
else if (s.over) { s.over = null; setOver(null) }
|
||||
@@ -104,11 +112,13 @@ export default function useHabitDrag({ onDrop }) {
|
||||
if (instant) {
|
||||
st.current.active = true
|
||||
setDragItem(item)
|
||||
moveGhost(st.current.startX, st.current.startY)
|
||||
if (navigator.vibrate) navigator.vibrate(15)
|
||||
} else {
|
||||
st.current.timer = setTimeout(() => {
|
||||
st.current.active = true
|
||||
setDragItem(item)
|
||||
moveGhost(st.current.startX, st.current.startY)
|
||||
if (navigator.vibrate) navigator.vibrate(15)
|
||||
}, 400)
|
||||
}
|
||||
@@ -137,5 +147,5 @@ export default function useHabitDrag({ onDrop }) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}), [])
|
||||
|
||||
return { dragItem, over, bind, bindHandle, cancel: cleanup, justEnded }
|
||||
return { dragItem, over, bind, bindHandle, ghostRef, cancel: cleanup, justEnded }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user