Skip to content

Commit 6c74782

Browse files
Copilotmattleibow
andcommitted
Remove isResetting guard field; fix AnimationCompleted transition; add SKLottiePlayerTest
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
1 parent abd8c6a commit 6c74782

File tree

3 files changed

+360
-18
lines changed

3 files changed

+360
-18
lines changed

source/SkiaSharp.Extended/Lottie/SKLottiePlayer.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class SKLottiePlayer
1111
private Skottie.Animation? animation;
1212
private bool isInForwardPhase = true;
1313
private int repeatsCompleted = 0;
14-
private bool isResetting;
1514

1615
private TimeSpan _progress;
1716

@@ -116,10 +115,6 @@ private void UpdateProgress(TimeSpan progress)
116115

117116
animation.SeekFrameTime(progress.TotalSeconds);
118117

119-
// Skip completion/repeat logic during Reset to avoid spurious events
120-
if (isResetting)
121-
return;
122-
123118
var repeat = Repeat;
124119
var duration = Duration;
125120

@@ -170,29 +165,27 @@ private void UpdateProgress(TimeSpan progress)
170165
isInForwardPhase = !isInForwardPhase;
171166
}
172167

168+
var prevIsComplete = IsComplete;
173169
IsComplete =
174170
isFinishedRun &&
175171
repeatsCompleted >= totalRepeatCount;
176172

177-
if (IsComplete)
173+
if (IsComplete && !prevIsComplete)
178174
AnimationCompleted?.Invoke(this, EventArgs.Empty);
179175
}
180176
}
181177

182178
private void Reset()
183179
{
184-
isResetting = true;
185-
try
186-
{
187-
isInForwardPhase = true;
188-
repeatsCompleted = 0;
180+
isInForwardPhase = true;
181+
repeatsCompleted = 0;
182+
IsComplete = false;
189183

190-
Duration = animation?.Duration ?? TimeSpan.Zero;
191-
Seek(AnimationSpeed < 0 ? Duration : TimeSpan.Zero);
192-
}
193-
finally
194-
{
195-
isResetting = false;
196-
}
184+
Duration = animation?.Duration ?? TimeSpan.Zero;
185+
186+
// Directly set the initial position without triggering completion logic.
187+
_progress = AnimationSpeed < 0 ? Duration : TimeSpan.Zero;
188+
animation?.SeekFrameTime(_progress.TotalSeconds);
189+
AnimationUpdated?.Invoke(this, EventArgs.Empty);
197190
}
198191
}

0 commit comments

Comments
 (0)