Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useTransition): fix regression with non-linear transition functions #2973

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/core/useTransition/index.test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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