behaves similarly to signals but instead will interpolate the value smoothly with the ability to cancel
0
const duration = useSignal(500)
const currentValue = useTween(0)
const nextValue = useSignal(0)
const hasFinished = useSignal(false)
const onUpdateValue = async () => {
hasFinished.value = false
await currentValue.set(nextValue, {
duration,
})
hasFinished.value = true
}
const onCancel = () => {
currentValue.set(nextValue, {
duration: 0,
})
hasFinished.value = true
}
const const currentValue: TweenSignal<number>
currentValue = useTween<number>(initial: number, options?: TweenedOptions<number> | undefined, displayName?: string): TweenSignal<number>
useTween(0)
interface interface TweenedOptions<T>
TweenedOptions<function (type parameter) T in TweenedOptions<T>
T> {
TweenedOptions<T>.delay?: number | undefined
delay?: number
TweenedOptions<T>.duration?: number | ((from: T, to: T) => number) | undefined
duration?: number | ((from: T
from: function (type parameter) T in TweenedOptions<T>
T, to: T
to: function (type parameter) T in TweenedOptions<T>
T) => number)
TweenedOptions<T>.easing?: ((t: number) => number) | undefined
easing?: (t: number
t: number) => number
TweenedOptions<T>.interpolate?: ((a: T, b: T) => (t: number) => T) | undefined
interpolate?: (a: T
a: function (type parameter) T in TweenedOptions<T>
T, b: T
b: function (type parameter) T in TweenedOptions<T>
T) => (t: number
t: number) => function (type parameter) T in TweenedOptions<T>
T
}