Skip to content

Commit

Permalink
Merge pull request facebookarchive#196 from b3ll/master
Browse files Browse the repository at this point in the history
Blockified POPAnimationDelegate
  • Loading branch information
Kimon Tsinteris committed Jan 12, 2015
2 parents 2407ef6 + b116b7d commit f1e2d53
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pop/POPAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,26 @@
*/
@property (readonly, nonatomic) POPAnimationTracer *tracer;

/**
@abstract Optional block called on animation start.
*/
@property (copy, nonatomic) void (^animationDidStartBlock)(POPAnimation *anim);

/**
@abstract Optional block called when value meets or exceeds to value.
*/
@property (copy, nonatomic) void (^animationDidReachToValueBlock)(POPAnimation *anim);

/**
@abstract Optional block called on animation completion.
*/
@property (copy, nonatomic) void (^completionBlock)(POPAnimation *anim, BOOL finished);

/**
@abstract Optional block called each frame animation is applied.
*/
@property (copy, nonatomic) void (^animationDidApplyBlock)(POPAnimation *anim);

/**
@abstract Flag indicating whether animation should be removed on completion.
@discussion Setting to NO can facilitate animation reuse. Defaults to YES.
Expand Down
3 changes: 3 additions & 0 deletions pop/POPAnimation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ - (void)setAutoreverses:(BOOL)autoreverses
}

FB_PROPERTY_GET(POPAnimationState, type, POPAnimationType);
DEFINE_RW_PROPERTY_OBJ_COPY(POPAnimationState, animationDidStartBlock, setAnimationDidStartBlock:, POPAnimationDidStartBlock);
DEFINE_RW_PROPERTY_OBJ_COPY(POPAnimationState, animationDidReachToValueBlock, setAnimationDidReachToValueBlock:, POPAnimationDidReachToValueBlock);
DEFINE_RW_PROPERTY_OBJ_COPY(POPAnimationState, completionBlock, setCompletionBlock:, POPAnimationCompletionBlock);
DEFINE_RW_PROPERTY_OBJ_COPY(POPAnimationState, animationDidApplyBlock, setAnimationDidApplyBlock:, POPAnimationDidApplyBlock);
DEFINE_RW_PROPERTY_OBJ_COPY(POPAnimationState, name, setName:, NSString*);
DEFINE_RW_PROPERTY(POPAnimationState, beginTime, setBeginTime:, CFTimeInterval);
DEFINE_RW_FLAG(POPAnimationState, removedOnCompletion, removedOnCompletion, setRemovedOnCompletion:);
Expand Down
24 changes: 24 additions & 0 deletions pop/POPAnimationInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ typedef struct
bool reached;
} POPProgressMarker;

typedef void (^POPAnimationDidStartBlock)(POPAnimation *anim);
typedef void (^POPAnimationDidReachToValueBlock)(POPAnimation *anim);
typedef void (^POPAnimationCompletionBlock)(POPAnimation *anim, BOOL finished);
typedef void (^POPAnimationDidApplyBlock)(POPAnimation *anim);

@interface POPAnimation()
- (instancetype)_init;
Expand Down Expand Up @@ -199,7 +202,10 @@ struct _POPAnimationState
CFTimeInterval startTime;
CFTimeInterval lastTime;
id __weak delegate;
POPAnimationDidStartBlock animationDidStartBlock;
POPAnimationDidReachToValueBlock animationDidReachToValueBlock;
POPAnimationCompletionBlock completionBlock;
POPAnimationDidApplyBlock animationDidApplyBlock;
NSMutableDictionary *dict;
POPAnimationTracer *tracer;
CGFloat progress;
Expand Down Expand Up @@ -232,7 +238,10 @@ struct _POPAnimationState
startTime(0),
lastTime(0),
delegate(nil),
animationDidStartBlock(nil),
animationDidReachToValueBlock(nil),
completionBlock(nil),
animationDidApplyBlock(nil),
dict(nil),
tracer(nil),
progress(0),
Expand All @@ -258,7 +267,10 @@ struct _POPAnimationState
name = nil;
dict = nil;
tracer = nil;
animationDidStartBlock = NULL;
animationDidReachToValueBlock = NULL;
completionBlock = NULL;
animationDidApplyBlock = NULL;
}

bool isCustom() {
Expand Down Expand Up @@ -364,6 +376,12 @@ struct _POPAnimationState
ActionEnabler enabler;
[delegate pop_animationDidStart:self];
}

POPAnimationDidStartBlock block = animationDidStartBlock;
if (block != NULL) {
ActionEnabler enabler;
block(self);
}

if (tracing) {
[tracer didStart];
Expand Down Expand Up @@ -451,6 +469,12 @@ struct _POPAnimationState
ActionEnabler enabler;
[delegate pop_animationDidApply:self];
}

POPAnimationDidApplyBlock block = animationDidApplyBlock;
if (block != NULL) {
ActionEnabler enabler;
block(self);
}
}

virtual void reset(bool all) {
Expand Down
6 changes: 6 additions & 0 deletions pop/POPPropertyAnimationInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ struct _POPPropertyAnimationState : _POPAnimationState
[delegate pop_animationDidReachToValue:self];
}

POPAnimationDidReachToValueBlock block = animationDidReachToValueBlock;
if (block != NULL) {
ActionEnabler enabler;
block(self);
}

if (tracing) {
[tracer didReachToValue:POPBox(currentValue(), valueType, true)];
}
Expand Down

0 comments on commit f1e2d53

Please sign in to comment.