From f593d8c7e21c8d69ad092b44a7bd9d64140de362 Mon Sep 17 00:00:00 2001 From: HF Date: Thu, 29 Apr 2021 12:50:33 +0200 Subject: [PATCH] debug windows on phones --- src/components/Window.jsx | 85 +++++++++++++++++++--------- src/controls/PixelPainterControls.js | 3 + 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/src/components/Window.jsx b/src/components/Window.jsx index 0550ae8..ac35212 100644 --- a/src/components/Window.jsx +++ b/src/components/Window.jsx @@ -3,7 +3,7 @@ * @flow */ -import React, { useCallback } from 'react'; +import React, { useCallback, useRef, useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { @@ -19,39 +19,57 @@ import COMPONENTS from './windows'; const selectWindowById = (state, windowId) => state.windows.windows.find((win) => win.windowId === windowId); const Window = ({ id }) => { + const titleBarRef = useRef(null); + const win = useSelector((state) => selectWindowById(state, id)); const dispatch = useDispatch(); const startMove = useCallback((event) => { - event.preventDefault(); - dispatch(focusWindow(id)); + try { + event.stopPropagation(); + dispatch(focusWindow(id)); + console.log('startMove'); - let { - clientX: startX, - clientY: startY, - } = event; - const move = (evt) => { - const { - clientX: curX, - clientY: curY, - } = evt; - dispatch(moveWindow(id, curX - startX, curY - startY)); - startX = curX; - startY = curY; - }; - document.addEventListener('mousemove', move); - const stopMove = () => { - document.removeEventListener('mousemove', move); - document.removeEventListener('mouseup', stopMove); - document.removeEventListener('touchcancel', stopMove); - }; - document.addEventListener('mouseup', stopMove); - document.addEventListener('touchcancel', stopMove); + let { + clientX: startX, + clientY: startY, + } = event.touches ? event.touches[0] : evt; + const move = (evt) => { + evt.stopPropagation(); + try { + const { + clientX: curX, + clientY: curY, + } = evt.touches ? evt.touches[0] : evt; + console.log(`move by ${curX-startX} - ${curY - startY}`); + dispatch(moveWindow(id, curX - startX, curY - startY)); + startX = curX; + startY = curY; + } catch (e) { + console.log(e); + } + }; + document.addEventListener('mousemove', move); + document.addEventListener('touchmove', move); + const stopMove = (evt) => { + evt.stopPropagation(); + console.log('stopMove'); + document.removeEventListener('mousemove', move); + document.removeEventListener('touchmove', move); + document.removeEventListener('mouseup', stopMove); + document.removeEventListener('touchcancel', stopMove); + document.removeEventListener('touchend', stopMove); + }; + document.addEventListener('mouseup', stopMove); + document.addEventListener('touchcancel', stopMove); + document.addEventListener('touchend', stopMove); + } catch (e) { + console.log(e); + } }, []); const startResize = useCallback((event) => { - event.preventDefault(); dispatch(focusWindow(id)); let { @@ -79,6 +97,19 @@ const Window = ({ id }) => { document.addEventListener('touchend', stopResize); }, []); + useEffect(() => { + if (titleBarRef && titleBarRef.current) { + console.log('add listener') + console.log(titleBarRef.current); + titleBarRef.current.addEventListener('mousedown', startMove, {passive: false}); + titleBarRef.current.addEventListener('touchstart', startMove, {passive: false}); + } + return () => { + titleBarRef.current.removeEventListener('mousedown', startMove); + titleBarRef.current.removeEventListener('touchstart', startMove); + }; + }, [titleBarRef, startMove]); + const clone = (evt) => { evt.stopPropagation(); evt.preventDefault(); @@ -125,8 +156,7 @@ const Window = ({ id }) => { >
{ onMouseDown={startResize} onTouchStart={startResize} className="win-resize" + touchAction="none" > ▨
diff --git a/src/controls/PixelPainterControls.js b/src/controls/PixelPainterControls.js index a6b8dfe..3035d94 100644 --- a/src/controls/PixelPainterControls.js +++ b/src/controls/PixelPainterControls.js @@ -227,6 +227,7 @@ class PixelPlainterControls { onTouchStart(event: TouchEvent) { event.preventDefault(); event.stopPropagation(); + console.log('PixelPlainterControls touch start'); document.activeElement.blur(); this.clickTapStartTime = Date.now(); @@ -257,6 +258,7 @@ class PixelPlainterControls { onTouchEnd(event: TouchEvent) { event.preventDefault(); event.stopPropagation(); + console.log('PixelPlainterControls touch end'); const { store } = this; if (event.touches.length === 0 && this.isClicking) { @@ -293,6 +295,7 @@ class PixelPlainterControls { onTouchMove(event: TouchEvent) { event.preventDefault(); event.stopPropagation(); + console.log('PixelPlainterControls touch move'); const multiTouch = (event.touches.length > 1);