Skip to content

Commit

Permalink
Merge pull request #211 from setaman/v2-fix-transition-for-safari
Browse files Browse the repository at this point in the history
fix: initial animation/transition on Safari
  • Loading branch information
setaman committed Oct 28, 2023
2 parents b60a35c + dbfc80b commit 1802cf8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 95 deletions.
6 changes: 3 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
<input type="checkbox" v-model="circles[3].loading" />
</div>-->
<div style="border: 1px solid red; display: inline-block">
<ve-progress :progress="progress" animation="rs 2000 2000" :legend-formatter="customFormatter" >
<ve-progress :progress="progress" animation="bounce 3000 300" :legend-formatter="customFormatter" :loading="loading" half >
<template #legend>
<span id="my-slot">Hello Circle</span>
</template>
</ve-progress>
<ve-progress
<!-- <ve-progress
:progress="progress"
:determinate="determinate"
:size="size"
Expand All @@ -67,7 +67,7 @@
<template #legend-caption>
<p>hello</p>
</template>
</ve-progress>
</ve-progress>-->
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/Circle/Circle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
</g>
</fade-in-transition>
<circle
ref="circleProgress"
class="ep-circle--progress"
:class="animationClass"
:r="radius"
Expand Down
4 changes: 4 additions & 0 deletions src/components/Circle/CircleContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ g.ep-circle--container {
.ep-circle--progress {
animation-timing-function: ease-in-out;
&.ep-animation-playing {
// Workaround only required for older Apple systems and Safari browser
transition: none !important;
}
&.animation__default {
animation-name: ep-progress--init__default;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Circle/HalfCircle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</g>
</fade-in-transition>
<path
ref="circleProgress"
:stroke-width="options.thickness"
class="ep-half-circle--progress ep-circle--progress"
:class="animationClass"
Expand Down
22 changes: 22 additions & 0 deletions src/components/Circle/circleMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
},
data: () => ({
isInitialized: false,
isAnimationPlaying: false,
}),
computed: {
progress() {
Expand Down Expand Up @@ -44,6 +45,7 @@ export default {

animationClass() {
return [
this.isAnimationPlaying && "ep-animation-playing",
`animation__${
!this.options.loading && this.dataIsAvailable && this.isInitialized ? this.options.animation.type : "none"
}`,
Expand Down Expand Up @@ -146,12 +148,32 @@ export default {
getBounceInOffset() {
return this.circumference - this.progressOffset < 100 ? this.progressOffset : this.progressOffset + 100;
},
toggleIsAnimationPlaying() {
this.$nextTick(() => {
this.isAnimationPlaying = !this.isAnimationPlaying;
});
},
},
async mounted() {
const circle = this.$refs.circleProgress;
if (circle) {
// this is only required for older MacOS/IOS versions and Safari. On Apple system the transition is triggered
// right after initial animation causing the progress line rendered twice. So we track animation state to
// add/remove CSS transition properties
circle.addEventListener("animationstart", this.toggleIsAnimationPlaying, false);
circle.addEventListener("animationend", this.toggleIsAnimationPlaying, false);
}
if (!this.options.loading) {
// await initial delay before applying animations
await wait(this.options.animation.delay);
}
this.isInitialized = true;
},
unmounted() {
const circle = this.$refs.circleProgress;
if (circle) {
circle.removeEventListener("animationstart", this.toggleIsAnimationPlaying, false);
circle.removeEventListener("animationend", this.toggleIsAnimationPlaying, false);
}
},
};
92 changes: 0 additions & 92 deletions src/styles/animationsUsage.scss

This file was deleted.

0 comments on commit 1802cf8

Please sign in to comment.