Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Add support for removing added animations #42

Merged
merged 11 commits into from
Nov 15, 2017
Merged

Add support for removing added animations #42

merged 11 commits into from
Nov 15, 2017

Conversation

jverkoey
Copy link
Contributor

@jverkoey jverkoey commented Nov 13, 2017

This change introduces two new APIs:

  1. removeAllAnimations
  2. 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.

@jverkoey
Copy link
Contributor Author

Gentle ping.

@jverkoey
Copy link
Contributor Author

jverkoey commented Nov 14, 2017

Slightly less gentle ping @randallli @romoore @jgunaratne

Copy link
Contributor

@romoore romoore left a 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.

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

// Tracks animations that have been added to a layer.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#import "MDMRegisteredAnimation.h"

@implementation MDMAnimationRegistrar {
NSMapTable *_layersToRegisteredAnimation; // Map of [CALayer:MDMRegisteredAnimation]
Copy link
Contributor

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;

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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];
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jverkoey jverkoey merged commit 51ac34a into develop Nov 15, 2017
@jverkoey jverkoey deleted the registrar branch November 15, 2017 20:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants