feat:Add iOS animation callback

This commit is contained in:
pengfei.zhou 2019-12-02 11:07:45 +08:00
parent a94ed4d880
commit b12930605e

View File

@ -66,6 +66,17 @@ CGPathRef DoricCreateRoundedRectPath(CGRect bounds,
return path; return path;
} }
@interface AnimationCallback : NSObject <CAAnimationDelegate>
@property(nonatomic, strong) void (^endBlock)();
@end
@implementation AnimationCallback
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
if (self.endBlock) {
self.endBlock();
}
}
@end
@interface DoricViewNode () @interface DoricViewNode ()
@property(nonatomic, strong) NSMutableDictionary *callbackIds; @property(nonatomic, strong) NSMutableDictionary *callbackIds;
@ -314,6 +325,12 @@ - (void)doAnimation:(id)params withPromise:(DoricPromise *)promise {
CAAnimation *animation = [self parseAnimation:params]; CAAnimation *animation = [self parseAnimation:params];
animation.removedOnCompletion = NO; animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards; animation.fillMode = kCAFillModeForwards;
AnimationCallback *animationCallback = [[AnimationCallback new] also:^(AnimationCallback *it) {
it.endBlock = ^{
[promise resolve:nil];
};
}];
animation.delegate = animationCallback;
[self.view.layer addAnimation:animation forKey:nil]; [self.view.layer addAnimation:animation forKey:nil];
} }