Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"packages/*"
]
},
"funding": "https://motion.dev/tools/pricing",
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
Expand Down Expand Up @@ -38,4 +39,4 @@
"typescript": "^4.6.3"
},
"packageManager": "[email protected]"
}
}
1 change: 1 addition & 0 deletions packages/animation/src/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class Animation implements Omit<AnimationControls, "stop" | "duration"> {

// Rebase on delay
t = Math.max(t - delay, 0)

/**
* If this animation has finished, set the current time
* to the total duration.
Expand Down
9 changes: 5 additions & 4 deletions packages/config/waapi-polyfill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions packages/dom/src/animate/__tests__/animate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@ describe("animate", () => {
})
})

test.only("Applies initial keyframe if a reverse animation finishes", async () => {
const div = document.createElement("div")
const animation = animate(
div,
{ opacity: [0.2, 0.5] },
{ duration, direction: "reverse" }
)
await animation.finished.then(() => {
expect(div).toHaveStyle("opacity: 0.2")
})
})

test("Applies initial keyframe if a reverse animation finishes having been manually reversed", async () => {
const div = document.createElement("div")
const animation = animate(div, { opacity: [0.2, 0.5] }, { duration: 0.2 })

animation.reverse()

await animation.finished.then(() => {
expect(div).toHaveStyle("opacity: 0.2")
})
})

test("Applies initial keyframe if animation finishes on a repeat reverse", async () => {
const div = document.createElement("div")
const animation = animate(
div,
{ opacity: [0.2, 0.5] },
{ duration, repeat: 1, direction: "alternate-reverse" }
)
await animation.finished.then(() => {
expect(div).toHaveStyle("opacity: 0.2")
})
})

test("Applies transform template", async () => {
const div = document.createElement("div")
const animation = animate(div, { x: 1 }, { duration })
Expand Down
6 changes: 1 addition & 5 deletions packages/dom/src/animate/animate-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,9 @@ export function animateStyle(
})
}

const target = keyframes[keyframes.length - 1]
animation.finished
.then(() => {
// Apply styles to target
style.set(element, name, target)

// Ensure fill modes don't persist
animation.commitStyles()
animation.cancel()
})
.catch(noop)
Expand Down
7 changes: 7 additions & 0 deletions packages/motion/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Motion One adheres to [Semantic Versioning](http://semver.org/).

## [10.10.1] [Unreleased]

### Fixed

- Animations finishing in reverse apply their initial styles instead of their final styles by cancelling the animation. [Issue (sponsors only)](https://github.com/motiondivision/motionone/issues/51)
- When `Animation` polyfill is reversed, animation no longer finishes instantly. [Issue (sponsors only)](https://github.com/motiondivision/motionone/issues/50)

## [10.10.0] [2022-05-28]

### Added
Expand Down
1 change: 1 addition & 0 deletions packages/motion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"main": "dist/main.cjs.js",
"module": "dist/main.es.js",
"types": "types/index.d.ts",
"funding": "https://motion.dev/tools/pricing",
"keywords": [
"animation",
"motion",
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/vue/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNuxtConfig } from "nuxt3"
import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "nuxi dev"
},
"devDependencies": {
"nuxt3": "latest"
"nuxt": "npm:nuxt3@latest"
},
"dependencies": {
"@motionone/vue": "^10.10.0",
Expand Down
34 changes: 34 additions & 0 deletions playgrounds/vue/pages/examples/reverse.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div
ref="root"
style="
width: 100px;
border-radius: 20px;
background-color: #ff1231;
height: 100px;
"
></div>
<button @click="toggle">Toggle</button>
</template>

<script lang="ts">
import { animate } from "motion"

export default {
setup: () => {
const root = ref<HTMLElement | null>(null)

let animation

function toggle() {
if (!animation) {
animation = animate(root.value, { scaleY: 0 }, { duration: 1 })
} else {
animation.reverse()
}
}

return { root, toggle }
},
}
</script>
Loading