Skip to content
This repository was archived by the owner on Jan 10, 2020. It is now read-only.

Commit da1cd96

Browse files
renyu-iofacebook-github-bot
authored andcommitted
Added finished parameter in KFVectorLayer?s animationDidStopBlock
Summary: I just added finished parameter to the animationDidStopBlock to be sure, animation was really finished (because this block is called at least twice). Closes #77 Differential Revision: D4365439 Pulled By: LazyChild fbshipit-source-id: 06939a5bdd921777c65ed9e061632817d205aa78
1 parent 4caeb5d commit da1cd96

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

ios/keyframes/src/Layers/KFVectorLayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@property (strong, nonatomic) KFVector *faceModel;
2626
@property (copy, nonatomic) NSDictionary<NSString *, UIImage *> *imageAssets;
27-
@property (copy, nonatomic) void (^animationDidStopBlock)(void);
27+
@property (copy, nonatomic) void (^animationDidStopBlock)(BOOL finished);
2828

2929
/**
3030
* Path based face view initially starts off with frame stuck at 0.

ios/keyframes/src/Layers/KFVectorLayer.m

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#import "KFVectorFeatureLayer.h"
2020
#import "KFVectorGradientFeatureLayer.h"
2121

22-
@implementation KFVectorLayer {
22+
@implementation KFVectorLayer
23+
{
2324
CALayer *_containerLayer;
2425
CABasicAnimation *_mockAnimation;
2526
}
@@ -165,17 +166,23 @@ - (void)_setupFace:(KFVector *)vector
165166
}];
166167

167168
// 6) Add a mock animation for invoking stop callback.
168-
_mockAnimation = [CABasicAnimation animationWithKeyPath:@"hidden"];
169-
_mockAnimation.fromValue = @(NO);
170-
_mockAnimation.toValue = @(NO);
171-
_mockAnimation.duration = vector.animationFrameCount * 1.0 / vector.frameRate;
172-
_mockAnimation.repeatCount = 1;
173-
_mockAnimation.delegate = self;
174-
[_mockAnimation setValue:@"mock animation" forKey:@"animationKey"];
169+
_mockAnimation = [self _createMockAnimation];
175170

176171
[self _resetAnimations];
177172
}
178173

174+
- (CABasicAnimation *)_createMockAnimation
175+
{
176+
CABasicAnimation *mockAnimation = [CABasicAnimation animationWithKeyPath:@"hidden"];
177+
mockAnimation.fromValue = @(NO);
178+
mockAnimation.toValue = @(NO);
179+
mockAnimation.duration = _faceModel.animationFrameCount * 1.0 / _faceModel.frameRate;
180+
mockAnimation.repeatCount = 1;
181+
mockAnimation.delegate = self;
182+
[mockAnimation setValue:@"mock animation" forKey:@"animationKey"];
183+
return mockAnimation;
184+
}
185+
179186
- (void)_resetAnimations
180187
{
181188
self.speed = 0;
@@ -236,10 +243,15 @@ - (void)layoutSublayers
236243

237244
#pragma mark - CAAnimationDelegate
238245

239-
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
246+
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)finished
240247
{
241248
if ([anim valueForKey:@"animationKey"] == [_mockAnimation valueForKey:@"animationKey"] && _animationDidStopBlock) {
242-
_animationDidStopBlock();
249+
_animationDidStopBlock(finished);
250+
}
251+
if (finished) {
252+
// Recreating mock animation for invoking stop callback again
253+
_mockAnimation = [self _createMockAnimation];
254+
[self addAnimation:_mockAnimation forKey:[_mockAnimation valueForKey:@"animationKey"]];
243255
}
244256
}
245257

0 commit comments

Comments
 (0)