Skip to content

Commit

Permalink
Merge pull request #332 from airbnb/btw/LoopanimationFix
Browse files Browse the repository at this point in the history
Fix for setting loop animation mid-flight
  • Loading branch information
buba447 committed Aug 3, 2017
2 parents 973ec4e + 2726804 commit 173e6d7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lottie-ios/Classes/Private/LOTAnimationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#import "LOTCompositionContainer.h"

@implementation LOTAnimationView {
CAAnimation *_playAnimation;
CABasicAnimation *_playAnimation;
LOTCompositionContainer *_compContainer;
NSBundle *_bundle;
}
Expand Down Expand Up @@ -231,7 +231,17 @@ - (void)pause {

- (void)setLoopAnimation:(BOOL)loopAnimation {
_loopAnimation = loopAnimation;
_playAnimation.repeatCount = _loopAnimation ? HUGE_VALF : 1;
if (_isAnimationPlaying) {

NSNumber *frame = [(LOTCompositionContainer *)_compContainer.presentationLayer currentFrame];
NSNumber *start = _playAnimation.fromValue;
NSNumber *end = _playAnimation.toValue;
[self _removeCurrentAnimationIfNecessary];

_compContainer.currentFrame = frame;
_animationProgress = frame.floatValue / (_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue);
[self playFromFrame:start toFrame:end withCompletion:self.completionBlock];
}
}

- (void)setProgressWithFrame:(nonnull NSNumber *)currentFrame {
Expand Down

0 comments on commit 173e6d7

Please sign in to comment.