Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update dependency react-use-gesture to v8.0.0-alpha.6 #745

Merged
merged 2 commits into from Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -134,7 +134,7 @@
"react-spring": "9.0.0-rc.3",
"react-three-fiber": "4.2.21",
"react-toast-notifications": "2.4.0",
"react-use-gesture": "8.0.0-alpha.4",
"react-use-gesture": "8.0.0-alpha.6",
"react-virtualized": "9.22.2",
"referentiel": "0.0.8",
"relay-compiler": "10.0.1",
Expand Down
6 changes: 4 additions & 2 deletions src/draggable-window.tsx
Expand Up @@ -87,8 +87,10 @@ export const DraggableWindow = ({
},
onMouseDown: ({ event }) => {
// on desktop we want to disable user-select while dragging
if (event.target && event.target instanceof HTMLElement) {
event.target.hasAttribute("data-draggable");
if (
event.target instanceof HTMLElement &&
event.target.hasAttribute("data-draggable")
) {
window.document.body.classList.add("user-select-disabled");
const onUnmount = () => {
window.document.body.classList.remove("user-select-disabled");
Expand Down
40 changes: 21 additions & 19 deletions src/map-view.tsx
@@ -1,6 +1,6 @@
import * as React from "react";
import * as THREE from "three";
import { Canvas, useLoader, useFrame, useUpdate } from "react-three-fiber";
import { Canvas, useLoader, useFrame, PointerEvent } from "react-three-fiber";
import { getOptimalDimensions } from "./util";
import { animated, useSpring, SpringValue } from "@react-spring/three";
import { useGesture } from "react-use-gesture";
Expand Down Expand Up @@ -566,28 +566,27 @@ export const MapView: React.FC<{

const bind = useGesture(
{
onPointerDown: (state) => {
onPointerDown: ({ event }) => {
if (pointerTimer.current) {
clearTimeout(pointerTimer.current);
}

// TODO: figure out why the typing do not show our point
// @ts-ignore
const point = (state as any).point as Vector3;
const pointerEvent = (event as any) as PointerEvent;

pointerTimer.current = setTimeout(() => {
if (dimensions) {
const factor =
dimensions.width / mapImageTexture.image.naturalWidth;
const x = calculateRealX(
// We need to convert the point to the point local to our element.
(point.x - spring.position.get()[0]) / spring.scale.get()[0],
(pointerEvent.point.x - spring.position.get()[0]) /
spring.scale.get()[0],
factor,
dimensions.width
);
const y = calculateRealY(
// We need to convert the point to the point local to our element.
(point.y - spring.position.get()[1]) / spring.scale.get()[1],
(pointerEvent.point.y - spring.position.get()[1]) /
spring.scale.get()[1],
factor,
dimensions.height
);
Expand Down Expand Up @@ -628,6 +627,17 @@ export const MapView: React.FC<{
});
return memo;
},
onMouseDown: ({ event }) => {
if (event.target instanceof HTMLCanvasElement) {
window.document.body.classList.add("user-select-disabled");
const onUnmount = () => {
window.document.body.classList.remove("user-select-disabled");
window.removeEventListener("mouseup", onUnmount);
};
window.addEventListener("mouseup", onUnmount);
onUnmountRef.current = onUnmount;
}
},
},
{}
);
Expand Down Expand Up @@ -693,30 +703,22 @@ export const MapView: React.FC<{
}, 100);
},
onWheel: ({ event }) => {
if (!event) {
return;
}
if (event.target instanceof HTMLCanvasElement === false) {
return;
}
let wheelEvent = event as React.WheelEvent;

event.preventDefault();

const [scale] = spring.scale.get();
const origin = [wheelEvent.clientX, wheelEvent.clientY] as [
number,
number
];
const origin = [event.clientX, event.clientY] as [number, number];

const wheel = wheelEvent.deltaY < 0 ? 1 : -1;
const wheel = event.deltaY < 0 ? 1 : -1;
const pinchScale = Math.max(0.1, Math.exp(wheel * 0.5) * scale);
const pinchDelta = pinchScale - scale;

updateZoom({ pinchDelta, pinchScale, origin });
},
onPinch: ({ movement, event, origin, last, cancel }) => {
if (!event || !origin) {
if (!origin) {
return;
}
if (event.target instanceof HTMLCanvasElement === false) {
Expand Down