-
-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Latest * Latest * Latest * Latest * Latest
- Loading branch information
1 parent
cc2ebee
commit dabfdcb
Showing
14 changed files
with
344 additions
and
45 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
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,131 @@ | ||
import { spring } from "framer-motion/dom" | ||
import { motion } from "framer-motion" | ||
import { useEffect, useState } from "react" | ||
|
||
const height = 100 | ||
const width = 500 | ||
const margin = 10 | ||
|
||
export function SpringVisualiser({ transition }: any) { | ||
const { duration, bounce } = { | ||
duration: transition.duration * 1000, | ||
bounce: transition.bounce, | ||
} | ||
const springResolver = spring({ | ||
bounce, | ||
visualDuration: duration, | ||
keyframes: [0, 1], | ||
}) | ||
|
||
let curveLine = `M${margin} ${margin + height}` | ||
let perceptualMarker = "" | ||
|
||
const step = 10 | ||
for (let i = 0; i <= width; i++) { | ||
const t = i * step | ||
|
||
if (t > duration && perceptualMarker === "") { | ||
perceptualMarker = `M${margin + i} ${margin} L${margin + i} ${ | ||
margin + height | ||
}` | ||
} | ||
|
||
curveLine += `L${margin + i} ${ | ||
margin + (height - springResolver.next(t).value * (height / 2)) | ||
}` | ||
} | ||
|
||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width={width + margin * 2} | ||
height={height + margin * 2} | ||
> | ||
<path | ||
d={curveLine} | ||
fill="transparent" | ||
strokeWidth="2" | ||
stroke="#AAAAAA" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
></path> | ||
<path | ||
d={perceptualMarker} | ||
fill="transparent" | ||
strokeWidth="2" | ||
stroke="#AAAAAA" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
></path> | ||
</svg> | ||
) | ||
} | ||
|
||
/** | ||
* An example of the tween transition type | ||
*/ | ||
|
||
const style = { | ||
width: 100, | ||
height: 100, | ||
background: "white", | ||
} | ||
export const App = () => { | ||
const [state, setState] = useState(false) | ||
|
||
const [duration, setDuration] = useState(1) | ||
const [bounce, setBounce] = useState(0.2) | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
setState(true) | ||
}, 300) | ||
}, [state]) | ||
|
||
return ( | ||
<> | ||
<div | ||
style={{ | ||
...style, | ||
transform: state ? "translateX(200px)" : "none", | ||
transition: "transform " + spring(duration, bounce), | ||
}} | ||
/> | ||
<motion.div | ||
animate={{ | ||
transform: state ? "translateX(200px)" : "translateX(0)", | ||
}} | ||
transition={{ | ||
visualDuration: duration, | ||
bounce, | ||
type: "spring", | ||
}} | ||
style={style} | ||
/> | ||
<SpringVisualiser | ||
transition={{ | ||
duration, | ||
type: "spring", | ||
bounce, | ||
durationBasedSpring: true, | ||
}} | ||
/> | ||
<input | ||
type="range" | ||
min="0" | ||
max="1" | ||
step="0.01" | ||
value={bounce} | ||
onChange={(e) => setBounce(Number(e.target.value))} | ||
/> | ||
<input | ||
type="range" | ||
min="0" | ||
max="10" | ||
step="0.1" | ||
value={duration} | ||
onChange={(e) => setDuration(Number(e.target.value))} | ||
/> | ||
</> | ||
) | ||
} |
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
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
6 changes: 2 additions & 4 deletions
6
packages/framer-motion/src/animation/animators/waapi/utils/linear.ts
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
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
28 changes: 28 additions & 0 deletions
28
packages/framer-motion/src/animation/generators/spring/defaults.ts
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,28 @@ | ||
export const springDefaults = { | ||
// Default spring physics | ||
stiffness: 100, | ||
damping: 10, | ||
mass: 1.0, | ||
velocity: 0.0, | ||
|
||
// Default duration/bounce-based options | ||
duration: 800, // in ms | ||
bounce: 0.3, | ||
visualDuration: 0.3, // in seconds | ||
|
||
// Rest thresholds | ||
restSpeed: { | ||
granular: 0.01, | ||
default: 2, | ||
}, | ||
restDelta: { | ||
granular: 0.005, | ||
default: 0.5, | ||
}, | ||
|
||
// Limits | ||
minDuration: 0.01, // in seconds | ||
maxDuration: 10.0, // in seconds | ||
minDamping: 0.05, | ||
maxDamping: 1, | ||
} |
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
Oops, something went wrong.