Skip to content

Commit

Permalink
Merge pull request #257 from wey-gu/react-use-gesture/to/use-gesture/…
Browse files Browse the repository at this point in the history
…react

replace react-use-gesture to @use-gesture/react
  • Loading branch information
amcdnl authored Jul 26, 2024
2 parents c80e8ad + b94a0d3 commit 5e64581
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Stats } from 'glodrei';
import theme from './theme';
import { Preview } from '@storybook/react';
import React from 'react';

const withProvider = (Story, context) => (
<>
Expand Down
11 changes: 1 addition & 10 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dependencies": {
"@react-spring/three": "9.6.1",
"@react-three/fiber": "8.13.5",
"@use-gesture/react": "^10.3.1",
"camera-controls": "^2.8.3",
"classnames": "^2.5.1",
"d3-array": "^3.2.4",
Expand All @@ -68,7 +69,6 @@
"graphology-metrics": "^2.1.0",
"graphology-shortest-path": "^2.0.2",
"hold-event": "^0.2.0",
"react-use-gesture": "^9.1.3",
"reakeys": "^2.0.3",
"three": "^0.154.0",
"three-stdlib": "^2.23.13",
Expand Down
10 changes: 4 additions & 6 deletions src/utils/useDrag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useThree } from '@react-three/fiber';
import { useMemo } from 'react';
import { useGesture } from 'react-use-gesture';
import { useGesture } from '@use-gesture/react';
import { Vector2, Vector3, Plane } from 'three';
import { InternalGraphPosition } from '../types';

Expand Down Expand Up @@ -61,12 +61,10 @@ export const useDrag = ({
// Run user callback
onDragStart();
},
onDrag: ({ event }) => {
onDrag: ({ xy }) => {
// Compute normalized mouse coordinates (screen space)
const nx =
((event.clientX - (clientRect?.left ?? 0)) / size.width) * 2 - 1;
const ny =
-((event.clientY - (clientRect?.top ?? 0)) / size.height) * 2 + 1;
const nx = ((xy[0] - (clientRect?.left ?? 0)) / size.width) * 2 - 1;
const ny = -((xy[1] - (clientRect?.top ?? 0)) / size.height) * 2 + 1;

// Unlike the mouse from useThree, this works offscreen
mouse2D.set(nx, ny);
Expand Down

0 comments on commit 5e64581

Please sign in to comment.