Skip to content

Commit

Permalink
Fix for repeat on android
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn00 committed Oct 5, 2020
1 parent da3fc2e commit d05290b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Lottie.Forms/Lottie.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<RootNamespace>Lottie.Forms</RootNamespace>
<Description>Render After Effects animations natively on Android, iOS, MacOS, TVOs and UWP</Description>
<PackageId>Com.Airbnb.Xamarin.Forms.Lottie</PackageId>
<Version>4.0.2</Version>
<Version>4.0.4</Version>
<UseWPF Condition=" '$(OS)' == 'Windows_NT' ">true</UseWPF>
</PropertyGroup>

Expand Down
11 changes: 10 additions & 1 deletion Lottie.Forms/Platforms/Android/AnimationViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ protected override void OnElementChanged(ElementChangedEventArgs<AnimationView>

_animationView.Speed = e.NewElement.Speed;
_animationView.RepeatMode = (int)e.NewElement.RepeatMode;
_animationView.RepeatCount = e.NewElement.RepeatCount;
if (e.NewElement.RepeatMode == RepeatMode.Infinite)
_animationView.RepeatCount = int.MaxValue;
else
_animationView.RepeatCount = e.NewElement.RepeatCount;
if (!string.IsNullOrEmpty(e.NewElement.ImageAssetsFolder))
_animationView.ImageAssetsFolder = e.NewElement.ImageAssetsFolder;
_animationView.Scale = e.NewElement.Scale;
Expand Down Expand Up @@ -174,7 +177,13 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
_animationView.Speed = Element.Speed;

if (e.PropertyName == AnimationView.RepeatModeProperty.PropertyName)
{
_animationView.RepeatMode = (int)Element.RepeatMode;
if (Element.RepeatMode == RepeatMode.Infinite)
_animationView.RepeatCount = int.MaxValue;
else
_animationView.RepeatCount = Element.RepeatCount;
}

if (e.PropertyName == AnimationView.RepeatCountProperty.PropertyName)
_animationView.RepeatCount = Element.RepeatCount;
Expand Down
4 changes: 2 additions & 2 deletions Lottie.Forms/Platforms/Ios/AnimationViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ private void AnimationCompletionBlock(bool animationFinished)
Element.InvokeRepeatAnimation();
_animationView.PlayWithCompletion(AnimationCompletionBlock);
}
else if(Element.RepeatMode == RepeatMode.Restart && repeatCount < Element.RepeatCount)
else if (Element.RepeatMode == RepeatMode.Restart && repeatCount < Element.RepeatCount)
{
repeatCount++;
Element.InvokeRepeatAnimation();
_animationView.PlayWithCompletion(AnimationCompletionBlock);
}
else if(Element.RepeatMode == RepeatMode.Restart && repeatCount == Element.RepeatCount)
else if (Element.RepeatMode == RepeatMode.Restart && repeatCount == Element.RepeatCount)
{
repeatCount = 1;
}
Expand Down

0 comments on commit d05290b

Please sign in to comment.