diff --git a/src/components/Map.js b/src/components/Map.js index b20c74d..1f84066 100644 --- a/src/components/Map.js +++ b/src/components/Map.js @@ -34,17 +34,31 @@ function Map({ const [mapScale, setMapScale] = useState(1); useEffect(() => { - interact(".map").draggable({ - inertia: true, - listeners: { - move: event => { - setMapTranslate(previousMapTranslate => ({ - x: previousMapTranslate.x + event.dx, - y: previousMapTranslate.y + event.dy - })); + interact(".map") + .gesturable({ + listeners: { + move: event => { + setMapScale(previousMapScale => + Math.max(Math.min(previousMapScale + event.ds, maxZoom), minZoom) + ); + setMapTranslate(previousMapTranslate => ({ + x: previousMapTranslate.x + event.dx, + y: previousMapTranslate.y + event.dy + })); + } } - } - }); + }) + .draggable({ + inertia: true, + listeners: { + move: event => { + setMapTranslate(previousMapTranslate => ({ + x: previousMapTranslate.x + event.dx, + y: previousMapTranslate.y + event.dy + })); + } + } + }); interact(".map").on("doubletap", event => { event.preventDefault(); setMapTranslate({ x: 0, y: 0 }); @@ -54,8 +68,8 @@ function Map({ function handleZoom(event) { const deltaY = event.deltaY * zoomSpeed; - setMapScale(mapScale => - Math.max(Math.min(mapScale + deltaY, maxZoom), minZoom) + setMapScale(previousMapScale => + Math.max(Math.min(previousMapScale + deltaY, maxZoom), minZoom) ); } @@ -72,7 +86,9 @@ function Map({ flexGrow: 1, position: "relative", overflow: "hidden", - backgroundColor: "rgba(0, 0, 0, 0.1)" + backgroundColor: "rgba(0, 0, 0, 0.1)", + userSelect: "none", + touchAction: "none" }} bg="background" onWheel={handleZoom} @@ -109,7 +125,11 @@ function Map({ @@ -139,6 +159,7 @@ function Map({ tokenId={token.id} image={token.image} className={mapTokenClassName} + sx={{ position: "absolute" }} /> ))} diff --git a/src/components/ProxyToken.js b/src/components/ProxyToken.js index d264fb1..31b89c0 100644 --- a/src/components/ProxyToken.js +++ b/src/components/ProxyToken.js @@ -112,12 +112,12 @@ function ProxyToken({ tokenClassName, onProxyDragEnd, size }) { return ReactDOM.createPortal( ); } +Token.defaultProps = { + sx: {} +}; + export default Token; diff --git a/src/index.css b/src/index.css index 365684a..ad37599 100644 --- a/src/index.css +++ b/src/index.css @@ -1 +1,7 @@ @import url("https://fonts.googleapis.com/css?family=Bree+Serif|Pacifico&display=swap"); + +#root, +body, +html { + height: 100%; +} diff --git a/src/routes/Game.js b/src/routes/Game.js index 895e668..2def785 100644 --- a/src/routes/Game.js +++ b/src/routes/Game.js @@ -136,7 +136,7 @@ function Game() { } return ( - + diff --git a/src/routes/Home.js b/src/routes/Home.js index 43b7680..36061ce 100644 --- a/src/routes/Home.js +++ b/src/routes/Home.js @@ -19,11 +19,11 @@ function Home() { } return ( - + diff --git a/src/routes/Join.js b/src/routes/Join.js index c6a07ea..56959d7 100644 --- a/src/routes/Join.js +++ b/src/routes/Join.js @@ -17,11 +17,11 @@ function Join() { } return ( - +