-
Notifications
You must be signed in to change notification settings - Fork 17
Add support for removing added animations #42
Conversation
Gentle ping. |
Slightly less gentle ping @randallli @romoore @jgunaratne |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main implementation looks good to me. :) Feedback on a few documentation/comments, and hopefully unit tests in a follow-up.
src/private/MDMAnimationRegistrar.h
Outdated
#import <Foundation/Foundation.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
// Tracks animations that have been added to a layer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Would be nice to have a documentation for the interface and methods even though it's a private class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/private/MDMAnimationRegistrar.m
Outdated
#import "MDMRegisteredAnimation.h" | ||
|
||
@implementation MDMAnimationRegistrar { | ||
NSMapTable *_layersToRegisteredAnimation; // Map of [CALayer:MDMRegisteredAnimation] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Use lightweight generics?
NSMapTable<CALayer *, MDMRegisteredAnimation*> *_layersToRegisteredAnimation;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
#pragma mark - Private | ||
|
||
- (void)forEachAnimation:(void (^)(CALayer *, CABasicAnimation *, NSString *))work { | ||
// Copy the registered animations before iteration in case further modifications happen to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this comment, are you worried that the dictionary can be mutated while you are iterating over it? Are the work
blocks the source of mutation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - consider if we remove an animation, its associated completion block might get fired and a new animation might be registered as a result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks!
} | ||
|
||
- (BOOL)isEqual:(id)object { | ||
return [_key isEqual:object]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two registered animations are equal if they have the same key but different animations? Could you please add some basic unit tests for this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a convention in place for private API unit tests unfortunately, meaning we can't access the APIs from unit test targets without some change to both our podfile & bazel configs.
XCTAssertEqual(view.layer.opacity, 0.5) | ||
} | ||
|
||
#if swift(>=3.2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the XCTWaiter that requires swift 3.2? The "classic" approach is to run the main runloop - does that not work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
This change introduces two new APIs:
removeAllAnimations
stopAllAnimations
The difference between the two APIs is that one simply removes the animations, while the other commits the presentation layer value to the model layer value before removing the animation. The latter is primarily intended for use when implementing motion with gesture recognition.