S
SolidJS2d ago
tizu

@solid-primitives/spring: obtain velocity?

is there some way I can obtain the velocity of the spring? xy: I want to detect if the popup is being dragged faster than x pixels, to then dismiss in a "flick" mode
8 Replies
Andreas Roth
Andreas Roth15h ago
https://github.com/solidjs-community/solid-primitives/blob/main/packages/spring/src/index.ts Doesn't seem like it. It only returns the signal with the current value. You could copy the source code and adapt it accordingly.
GitHub
solid-primitives/packages/spring/src/index.ts at main · solidjs-com...
A library of high-quality primitives that extend SolidJS reactivity. - solidjs-community/solid-primitives
bigmistqke
bigmistqke14h ago
I guess you can always calculate it too outside the primitive (save time + previous value), but could be a cool addition to the primitive (wdyt @thetarnav ?)
thetarnav
thetarnav14h ago
you mean access to internals?
bigmistqke
bigmistqke14h ago
Uhu
thetarnav
thetarnav14h ago
yeah that sounds good but it’s usually difficult to keep the api “slick” unfortunately
bigmistqke
bigmistqke14h ago
I had something in my mind, but doesn't work actually. Maybe just calculating it in userland is the cleanest. Could do an option and then return { value, velocity } Or attach it to the signal
const spring = createSpring(...)
spring() // value
spring.velocity()
const spring = createSpring(...)
spring() // value
spring.velocity()
is a bit esoteric
thetarnav
thetarnav14h ago
yeah that’s what I mean also now you need to make velocity a separate signal
bigmistqke
bigmistqke14h ago
velocity could be () => { value(); return velocity }

Did you find this page helpful?