From 95043b0b9a336e8c782e6d95b47ca725685a9b70 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko <2277098+anoshenko@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:30:43 +0300 Subject: [PATCH] Fixed animation --- animationRun.go | 28 ++++++++++++++++++++-------- session.go | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/animationRun.go b/animationRun.go index 6ebbc8a..5e2955d 100644 --- a/animationRun.go +++ b/animationRun.go @@ -56,17 +56,22 @@ func (animation *animationData) finish() { } } - animation.view.Set(AnimationTag, animation.oldAnimation) + if animation.oldAnimation != nil { + animation.view.Set(AnimationTag, animation.oldAnimation) + animation.oldAnimation = nil + } else { + animation.view.Set(AnimationTag, "") + } animation.oldListeners = map[string][]func(View, string){} - animation.oldAnimation = nil + animation.view = nil animation.listener = nil } } func (animation *animationData) Stop() { - animation.finish() + animation.onAnimationCancel(animation.view, "") } func (animation *animationData) Pause() { @@ -89,10 +94,12 @@ func (animation *animationData) onAnimationStart(view View, _ string) { func (animation *animationData) onAnimationEnd(view View, _ string) { if animation.view != nil { - if animation.listener != nil { - animation.listener(animation.view, animation, AnimationEndEvent) - } + animationView := animation.view + listener := animation.listener animation.finish() + if listener != nil { + listener(animationView, animation, AnimationEndEvent) + } } } @@ -103,7 +110,12 @@ func (animation *animationData) onAnimationIteration(view View, _ string) { } func (animation *animationData) onAnimationCancel(view View, _ string) { - if animation.view != nil && animation.listener != nil { - animation.listener(animation.view, animation, AnimationCancelEvent) + if animation.view != nil { + animationView := animation.view + listener := animation.listener + animation.finish() + if listener != nil { + listener(animationView, animation, AnimationCancelEvent) + } } } diff --git a/session.go b/session.go index 5af9cb0..be59c03 100644 --- a/session.go +++ b/session.go @@ -521,7 +521,7 @@ func (session *sessionData) removeAnimation(keyframe string) { } if end > index { - session.animationCSS = css[:index] + css[end:] + session.animationCSS = strings.Trim(css[:index]+css[end:], "\n") if session.bridge != nil { session.bridge.setAnimationCSS(session.animationCSS) } else {