-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for dragover event handling
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useState } from 'react' | ||
import { Canvas } from '@react-three/fiber' | ||
import { a, useSpring } from '@react-spring/three' | ||
import { OrbitControls } from '@react-three/drei' | ||
|
||
export default function Box() { | ||
const [active, setActive] = useState(0) | ||
// create a common spring that will be used later to interpolate other values | ||
const { spring } = useSpring({ | ||
spring: active, | ||
config: { mass: 5, tension: 400, friction: 50, precision: 0.0001 }, | ||
}) | ||
// interpolate values from commong spring | ||
const scale = spring.to([0, 1], [1, 2]) | ||
const rotation = spring.to([0, 1], [0, Math.PI]) | ||
const color = active ? spring.to([0, 1], ['#6246ea', '#e45858']) : spring.to([0, 1], ['#620000', '#e40000']) | ||
return ( | ||
<Canvas> | ||
<a.mesh | ||
rotation-y={rotation} | ||
scale-x={scale} | ||
scale-z={scale} | ||
onDragOverEnter={() => setActive(1)} | ||
onDragOverLeave={() => setActive(0)}> | ||
<boxBufferGeometry /> | ||
<a.meshBasicMaterial color={color} /> | ||
</a.mesh> | ||
<OrbitControls /> | ||
</Canvas> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters