Skip to content

Commit

Permalink
fix(useTransition): fix regression with non-linear transition functio…
Browse files Browse the repository at this point in the history
…ns (#2973)
  • Loading branch information
scottbedard committed Apr 14, 2023
1 parent 47be62a commit 8b3300b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/core/useTransition/index.test.ts
Expand Up @@ -158,6 +158,26 @@ describe('useTransition', () => {
expect(transition.value).toBe(1)
})

it('supports non-linear custom easing functions', async () => {
const source = ref(0)
const easeInQuad = vi.fn(n => n * n)
const transition = useTransition(source, {
duration: 100,
transition: easeInQuad,
})

expect(easeInQuad).not.toBeCalled()

source.value = 1

await promiseTimeout(50)
expect(easeInQuad).toBeCalled()
expectBetween(transition.value, 0, 1)

await promiseTimeout(100)
expect(transition.value).toBe(1)
})

it('supports delayed transitions', async () => {
const source = ref(0)

Expand Down
4 changes: 3 additions & 1 deletion packages/core/useTransition/index.ts
Expand Up @@ -148,7 +148,9 @@ export function executeTransition<T extends number | number[]>(
const duration = toValue(options.duration) ?? 1000
const startedAt = Date.now()
const endAt = Date.now() + duration
const trans = toValue(options.transition) ?? linear
const trans = typeof options.transition === 'function'
? options.transition
: (toValue(options.transition) ?? linear)

const ease = typeof trans === 'function'
? trans
Expand Down

0 comments on commit 8b3300b

Please sign in to comment.