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

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Verkoeyen committed Nov 15, 2017
2 parents 9bb99ee + a76375d commit 6d13fe8
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module: MotionAnimator
module_version: 2.2.1
module_version: 2.3.0
sdk: iphonesimulator
umbrella_header: src/MotionAnimator.h
objc: true
github_url: https://github.com/material-motion/motion-animator-objc
github_file_prefix: https://github.com/material-motion/motion-animator-objc/tree/v2.2.1
github_file_prefix: https://github.com/material-motion/motion-animator-objc/tree/v2.3.0
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# 2.3.0

This minor release introduces new features for working with gestural interactions.

## New features

Added two new methods for removing and stopping running animations.

## Source changes

* [Add support for removing added animations (#42)](https://github.com/material-motion/motion-animator-objc/commit/51ac34ada49013590d1c79480256faef8017624e) (featherless)

## API changes

### MDMMotionAnimator

**new** method: `removeAllAnimations`

**new** method: `stopAllAnimations`

# 2.2.1

This patch release fixes a bug where CGPoint and CGSize spring animations would not properly extract
Expand Down
2 changes: 1 addition & 1 deletion MotionAnimator.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "MotionAnimator"
s.summary = "A Motion Animator creates performant, interruptible animations from motion specs."
s.version = "2.2.1"
s.version = "2.3.0"
s.authors = "The Material Motion Authors"
s.license = "Apache 2.0"
s.homepage = "https://github.com/material-motion/motion-animator-objc"
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- CatalogByConvention (2.2.0)
- MotionAnimator (2.2.1):
- MotionAnimator (2.3.0):
- MotionInterchange (~> 1.3)
- MotionInterchange (1.3.0)

Expand All @@ -14,7 +14,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
CatalogByConvention: 5df5831e48b8083b18570dcb804f20fd1c90694f
MotionAnimator: 32af4888186e2f5db5deef85939224a1d973b869
MotionAnimator: 133a697ee8c7e07f96553f641571bdb6ef698cb2
MotionInterchange: 988fc0011e4b806cc33f2fb4f9566f5eeb4159e8

PODFILE CHECKSUM: 3537bf01c11174928ac008c20fec4738722e96f3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
667A3F4C1DEE269400CB3A99 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 667A3F4A1DEE269400CB3A99 /* LaunchScreen.storyboard */; };
667A3F541DEE273000CB3A99 /* TableOfContents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 667A3F531DEE273000CB3A99 /* TableOfContents.swift */; };
6687264A1EF04B4C00113675 /* MotionAnimatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 668726491EF04B4C00113675 /* MotionAnimatorTests.swift */; };
66A6A6681FBA158000DE54CB /* AnimationRemovalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66A6A6671FBA158000DE54CB /* AnimationRemovalTests.swift */; };
66BF5A8F1FB0E4CB00E864F6 /* ImplicitAnimationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66BF5A8E1FB0E4CB00E864F6 /* ImplicitAnimationTests.swift */; };
66DD4BF51EEF0ECB00207119 /* CalendarCardExpansionExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 66DD4BF41EEF0ECB00207119 /* CalendarCardExpansionExample.m */; };
66DD4BF81EEF1C4B00207119 /* CalendarChipMotionSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 66DD4BF71EEF1C4B00207119 /* CalendarChipMotionSpec.m */; };
Expand Down Expand Up @@ -62,6 +63,7 @@
667A3F4D1DEE269400CB3A99 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
667A3F531DEE273000CB3A99 /* TableOfContents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableOfContents.swift; sourceTree = "<group>"; };
668726491EF04B4C00113675 /* MotionAnimatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MotionAnimatorTests.swift; sourceTree = "<group>"; };
66A6A6671FBA158000DE54CB /* AnimationRemovalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimationRemovalTests.swift; sourceTree = "<group>"; };
66BF5A8E1FB0E4CB00E864F6 /* ImplicitAnimationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImplicitAnimationTests.swift; sourceTree = "<group>"; };
66DD4BF31EEF0ECB00207119 /* CalendarCardExpansionExample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CalendarCardExpansionExample.h; sourceTree = "<group>"; };
66DD4BF41EEF0ECB00207119 /* CalendarCardExpansionExample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CalendarCardExpansionExample.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -208,6 +210,7 @@
66FD99F81EE9FBA000C53A82 /* unit */ = {
isa = PBXGroup;
children = (
66A6A6671FBA158000DE54CB /* AnimationRemovalTests.swift */,
66FD99F91EE9FBBE00C53A82 /* MotionAnimatorTests.m */,
668726491EF04B4C00113675 /* MotionAnimatorTests.swift */,
66BF5A8E1FB0E4CB00E864F6 /* ImplicitAnimationTests.swift */,
Expand Down Expand Up @@ -491,6 +494,7 @@
6625876C1FB4DB9C00BC7DF1 /* InitialVelocityTests.swift in Sources */,
660636021FACC24300C3DFB8 /* TimeScaleFactorTests.swift in Sources */,
66BF5A8F1FB0E4CB00E864F6 /* ImplicitAnimationTests.swift in Sources */,
66A6A6681FBA158000DE54CB /* AnimationRemovalTests.swift in Sources */,
6687264A1EF04B4C00113675 /* MotionAnimatorTests.swift in Sources */,
66FD99FA1EE9FBBE00C53A82 /* MotionAnimatorTests.m in Sources */,
);
Expand Down
17 changes: 17 additions & 0 deletions src/MDMMotionAnimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,21 @@ NS_SWIFT_NAME(MotionAnimator)
animations:(nonnull void (^)(void))animations
completion:(nullable void(^)(void))completion;

/**
Removes every animation added by this animator.
Removing animations in this manner will give the appearance of each animated layer property
instantaneously jumping to its animated destination.
*/
- (void)removeAllAnimations;

/**
Commits the presentation layer value to the model layer value for every active animation's key path
and then removes every animation.
This method is most commonly called in reaction to the initiation of a gesture so that any
in-flight animations are stopped at their current on-screen position.
*/
- (void)stopAllAnimations;

@end
26 changes: 13 additions & 13 deletions src/MDMMotionAnimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@

#import "CATransaction+MotionAnimator.h"
#import "private/CABasicAnimation+MotionAnimator.h"
#import "private/MDMAnimationRegistrar.h"
#import "private/MDMUIKitValueCoercion.h"
#import "private/MDMBlockAnimations.h"
#import "private/MDMDragCoefficient.h"

@implementation MDMMotionAnimator {
NSMutableArray *_tracers;
MDMAnimationRegistrar *_registrar;
}

- (instancetype)init {
self = [super init];
if (self) {
_registrar = [[MDMAnimationRegistrar alloc] init];
_timeScaleFactor = 1;
_additive = true;
}
Expand Down Expand Up @@ -93,23 +96,12 @@ - (void)animateWithTiming:(MDMMotionTiming)timing
animation.fillMode = kCAFillModeBackwards;
}

if (completion) {
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
}

// When we use a nil key, Core Animation will ensure that the animation is added with a
// unique key - this enables our additive animations to stack upon one another.
NSString *key = _additive ? nil : keyPath;
[layer addAnimation:animation forKey:key];
[_registrar addAnimation:animation toLayer:layer forKey:key completion:completion];

for (void (^tracer)(CALayer *, CAAnimation *) in _tracers) {
tracer(layer, animation);
}

if (completion) {
[CATransaction commit];
}
}
}

Expand Down Expand Up @@ -165,5 +157,13 @@ - (CGFloat)computedTimeScaleFactor {
return MDMSimulatorAnimationDragCoefficient() * timeScaleFactor;
}

@end
- (void)removeAllAnimations {
[_registrar removeAllAnimations];
}

- (void)stopAllAnimations {
[_registrar commitCurrentAnimationValuesToAllLayers];
[_registrar removeAllAnimations];
}

@end
38 changes: 38 additions & 0 deletions src/private/MDMAnimationRegistrar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2017-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

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

// Tracks and manipulates animations that have been added to a layer.
@interface MDMAnimationRegistrar : NSObject

// Invokes the layer's addAnimation:forKey: method with the provided animation and key and tracks
// its association. Upon completion of the animation, the provided optional completion block will be
// executed.
- (void)addAnimation:(nonnull CABasicAnimation *)animation
toLayer:(nonnull CALayer *)layer
forKey:(nonnull NSString *)key
completion:(void(^ __nullable)(void))completion;

// For every active animation, reads the associated layer's presentation layer key path and writes
// it to the layer.
- (void)commitCurrentAnimationValuesToAllLayers;

// Removes all active animations from their associated layer.
- (void)removeAllAnimations;

@end
102 changes: 102 additions & 0 deletions src/private/MDMAnimationRegistrar.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright 2017-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "MDMAnimationRegistrar.h"

#import "MDMRegisteredAnimation.h"

@implementation MDMAnimationRegistrar {
NSMapTable<CALayer *, NSMutableSet<MDMRegisteredAnimation *> *> *_layersToRegisteredAnimation;
}

- (instancetype)init {
self = [super init];
if (self) {
_layersToRegisteredAnimation = [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsWeakMemory
valueOptions:NSPointerFunctionsStrongMemory];
}
return self;
}

#pragma mark - Private

- (void)forEachAnimation:(void (^)(CALayer *, CABasicAnimation *, NSString *))work {
// Copy the registered animations before iteration in case further modifications happen to the
// registered animations. Consider if we remove an animation, its associated completion block
// might invoke logic that adds a new animation, potentially modifying our collections.
for (CALayer *layer in [_layersToRegisteredAnimation copy]) {
NSSet *keyPathAnimations = [_layersToRegisteredAnimation objectForKey:layer];
for (MDMRegisteredAnimation *keyPathAnimation in [keyPathAnimations copy]) {
if (![keyPathAnimation.animation isKindOfClass:[CABasicAnimation class]]) {
continue;
}

work(layer, [keyPathAnimation.animation copy], keyPathAnimation.key);
}
}
}

#pragma mark - Public

- (void)addAnimation:(CABasicAnimation *)animation
toLayer:(CALayer *)layer
forKey:(NSString *)key
completion:(void(^)(void))completion {
if (key == nil) {
key = [NSUUID UUID].UUIDString;
}

NSMutableSet *animatedKeyPaths = [_layersToRegisteredAnimation objectForKey:layer];
if (!animatedKeyPaths) {
animatedKeyPaths = [[NSMutableSet alloc] init];
[_layersToRegisteredAnimation setObject:animatedKeyPaths forKey:layer];
}
MDMRegisteredAnimation *keyPathAnimation =
[[MDMRegisteredAnimation alloc] initWithKey:key animation:animation];
[animatedKeyPaths addObject:keyPathAnimation];

[CATransaction begin];
[CATransaction setCompletionBlock:^{
[animatedKeyPaths removeObject:keyPathAnimation];

if (completion) {
completion();
}
}];

[layer addAnimation:animation forKey:key];

[CATransaction commit];
}

- (void)commitCurrentAnimationValuesToAllLayers {
[self forEachAnimation:^(CALayer *layer, CABasicAnimation *animation, NSString *key) {
id presentationLayer = [layer presentationLayer];
if (presentationLayer != nil) {
id presentationValue = [presentationLayer valueForKeyPath:animation.keyPath];
[layer setValue:presentationValue forKeyPath:animation.keyPath];
}
}];
}

- (void)removeAllAnimations {
[self forEachAnimation:^(CALayer *layer, CABasicAnimation *animation, NSString *key) {
[layer removeAnimationForKey:key];
}];
[_layersToRegisteredAnimation removeAllObjects];
}

@end
28 changes: 28 additions & 0 deletions src/private/MDMRegisteredAnimation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2017-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

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

@interface MDMRegisteredAnimation : NSObject

- (instancetype)initWithKey:(NSString *)key animation:(CABasicAnimation *)animation;

@property(nonatomic, copy, readonly) NSString *key;

@property(nonatomic, strong, readonly) CABasicAnimation *animation;

@end
39 changes: 39 additions & 0 deletions src/private/MDMRegisteredAnimation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2017-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "MDMRegisteredAnimation.h"

@implementation MDMRegisteredAnimation

- (instancetype)initWithKey:(NSString *)key animation:(CABasicAnimation *)animation {
self = [super init];
if (self) {
_key = [key copy];
_animation = animation;
}
return self;
}

- (NSUInteger)hash {
return _key.hash;
}

- (BOOL)isEqual:(id)object {
return [_key isEqual:object];
}

@end

Loading

0 comments on commit 6d13fe8

Please sign in to comment.