Skip to content

Commit 1802cf8

Browse files
authored
Merge pull request #211 from setaman/v2-fix-transition-for-safari
fix: initial animation/transition on Safari
2 parents b60a35c + dbfc80b commit 1802cf8

File tree

6 files changed

+31
-95
lines changed

6 files changed

+31
-95
lines changed

src/App.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
<input type="checkbox" v-model="circles[3].loading" />
4545
</div>-->
4646
<div style="border: 1px solid red; display: inline-block">
47-
<ve-progress :progress="progress" animation="rs 2000 2000" :legend-formatter="customFormatter" >
47+
<ve-progress :progress="progress" animation="bounce 3000 300" :legend-formatter="customFormatter" :loading="loading" half >
4848
<template #legend>
4949
<span id="my-slot">Hello Circle</span>
5050
</template>
5151
</ve-progress>
52-
<ve-progress
52+
<!-- <ve-progress
5353
:progress="progress"
5454
:determinate="determinate"
5555
:size="size"
@@ -67,7 +67,7 @@
6767
<template #legend-caption>
6868
<p>hello</p>
6969
</template>
70-
</ve-progress>
70+
</ve-progress>-->
7171
</div>
7272
</div>
7373
</div>

src/components/Circle/Circle.vue

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
</g>
5555
</fade-in-transition>
5656
<circle
57+
ref="circleProgress"
5758
class="ep-circle--progress"
5859
:class="animationClass"
5960
:r="radius"

src/components/Circle/CircleContainer.vue

+4
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ g.ep-circle--container {
257257
258258
.ep-circle--progress {
259259
animation-timing-function: ease-in-out;
260+
&.ep-animation-playing {
261+
// Workaround only required for older Apple systems and Safari browser
262+
transition: none !important;
263+
}
260264
&.animation__default {
261265
animation-name: ep-progress--init__default;
262266
}

src/components/Circle/HalfCircle.vue

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</g>
4848
</fade-in-transition>
4949
<path
50+
ref="circleProgress"
5051
:stroke-width="options.thickness"
5152
class="ep-half-circle--progress ep-circle--progress"
5253
:class="animationClass"

src/components/Circle/circleMixin.js

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default {
1313
},
1414
data: () => ({
1515
isInitialized: false,
16+
isAnimationPlaying: false,
1617
}),
1718
computed: {
1819
progress() {
@@ -44,6 +45,7 @@ export default {
4445

4546
animationClass() {
4647
return [
48+
this.isAnimationPlaying && "ep-animation-playing",
4749
`animation__${
4850
!this.options.loading && this.dataIsAvailable && this.isInitialized ? this.options.animation.type : "none"
4951
}`,
@@ -146,12 +148,32 @@ export default {
146148
getBounceInOffset() {
147149
return this.circumference - this.progressOffset < 100 ? this.progressOffset : this.progressOffset + 100;
148150
},
151+
toggleIsAnimationPlaying() {
152+
this.$nextTick(() => {
153+
this.isAnimationPlaying = !this.isAnimationPlaying;
154+
});
155+
},
149156
},
150157
async mounted() {
158+
const circle = this.$refs.circleProgress;
159+
if (circle) {
160+
// this is only required for older MacOS/IOS versions and Safari. On Apple system the transition is triggered
161+
// right after initial animation causing the progress line rendered twice. So we track animation state to
162+
// add/remove CSS transition properties
163+
circle.addEventListener("animationstart", this.toggleIsAnimationPlaying, false);
164+
circle.addEventListener("animationend", this.toggleIsAnimationPlaying, false);
165+
}
151166
if (!this.options.loading) {
152167
// await initial delay before applying animations
153168
await wait(this.options.animation.delay);
154169
}
155170
this.isInitialized = true;
156171
},
172+
unmounted() {
173+
const circle = this.$refs.circleProgress;
174+
if (circle) {
175+
circle.removeEventListener("animationstart", this.toggleIsAnimationPlaying, false);
176+
circle.removeEventListener("animationend", this.toggleIsAnimationPlaying, false);
177+
}
178+
},
157179
};

src/styles/animationsUsage.scss

-92
This file was deleted.

0 commit comments

Comments
 (0)