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

Commit

Permalink
Revert "Update with ObjC implementation."
Browse files Browse the repository at this point in the history
This reverts commit be7f908.
  • Loading branch information
jverkoey committed Dec 4, 2017
1 parent be7f908 commit f55625d
Show file tree
Hide file tree
Showing 23 changed files with 403 additions and 410 deletions.
1 change: 0 additions & 1 deletion Podfile
Expand Up @@ -5,7 +5,6 @@ target "MotionAnimatorCatalog" do
pod 'CatalogByConvention'
pod 'MotionAnimator', :path => './'
project 'examples/apps/Catalog/MotionAnimatorCatalog.xcodeproj'
pod 'MotionInterchange', :path => '../motion-interchange-objc/'
end

target "UnitTests" do
Expand Down
9 changes: 3 additions & 6 deletions Podfile.lock
Expand Up @@ -2,24 +2,21 @@ PODS:
- CatalogByConvention (2.2.0)
- MotionAnimator (2.6.0):
- MotionInterchange (~> 1.3)
- MotionInterchange (1.4.0)
- MotionInterchange (1.3.0)

DEPENDENCIES:
- CatalogByConvention
- MotionAnimator (from `./`)
- MotionInterchange (from `../motion-interchange-objc/`)

EXTERNAL SOURCES:
MotionAnimator:
:path: ./
MotionInterchange:
:path: ../motion-interchange-objc/

SPEC CHECKSUMS:
CatalogByConvention: 5df5831e48b8083b18570dcb804f20fd1c90694f
MotionAnimator: a4b0ba87a674bb3e89e25f0530b7e80a204ac1c1
MotionInterchange: 35e0fd286ceab53dd4ee03494b3fcafa6a70637a
MotionInterchange: 988fc0011e4b806cc33f2fb4f9566f5eeb4159e8

PODFILE CHECKSUM: f354f45cd3f9eb0e6ac9a2bfd9429945eae8c0ad
PODFILE CHECKSUM: 3537bf01c11174928ac008c20fec4738722e96f3

COCOAPODS: 1.3.1
34 changes: 17 additions & 17 deletions examples/CalendarCardExpansionExample.m
Expand Up @@ -20,12 +20,12 @@

#import "MotionAnimator.h"

// This example demonstrates how to use a motion traits specification to build a complex
// This example demonstrates how to use a motion timing specification to build a complex
// bi-directional animation using the MDMMotionAnimator object. MDMMotionAnimator is designed for
// building fine-tuned explicit animations. Unlike UIView's implicit animation API, which can be
// used to cause cascading animations on a variety of properties, MDMMotionAnimator will always add
// exactly one animation per key path to the layer. This means you don't get as much for "free", but
// you do gain more control over the traits and motion of the animation.
// you do gain more control over the timing and motion of the animation.

@implementation CalendarCardExpansionExampleViewController {
// In a real-world scenario we'd likely create a separate view to manage all of these subviews so
Expand All @@ -40,57 +40,57 @@ @implementation CalendarCardExpansionExampleViewController {
- (void)didTap {
_expanded = !_expanded;

id<CalendarChipTiming> traits = (_expanded
? CalendarChipMotionSpec.expansion
: CalendarChipMotionSpec.collapse);
CalendarChipTiming timing = (_expanded
? CalendarChipMotionSpec.expansion
: CalendarChipMotionSpec.collapse);

MDMMotionAnimator *animator = [[MDMMotionAnimator alloc] init];
animator.shouldReverseValues = !_expanded;
animator.beginFromCurrentState = YES;

[animator animateWithTraits:traits.navigationBarY animations:^{
[animator animateWithTiming:timing.navigationBarY animations:^{
[self.navigationController setNavigationBarHidden:_expanded animated:YES];
}];

CGRect chipFrame = [self frameForChip];
CGRect headerFrame = [self frameForHeader];

// Animate the chip itself.
[animator animateWithTraits:traits.chipHeight
[animator animateWithTiming:timing.chipHeight
toLayer:_chipView.layer
withValues:@[ @(chipFrame.size.height), @(headerFrame.size.height) ]
keyPath:MDMKeyPathHeight];
[animator animateWithTraits:traits.chipWidth
[animator animateWithTiming:timing.chipWidth
toLayer:_chipView.layer
withValues:@[ @(chipFrame.size.width), @(headerFrame.size.width) ]
keyPath:MDMKeyPathWidth];
[animator animateWithTraits:traits.chipWidth
[animator animateWithTiming:timing.chipWidth
toLayer:_chipView.layer
withValues:@[ @(CGRectGetMidX(chipFrame)), @(CGRectGetMidX(headerFrame)) ]
keyPath:MDMKeyPathX];
[animator animateWithTraits:traits.chipY
[animator animateWithTiming:timing.chipY
toLayer:_chipView.layer
withValues:@[ @(CGRectGetMidY(chipFrame)), @(CGRectGetMidY(headerFrame)) ]
keyPath:MDMKeyPathY];
[animator animateWithTraits:traits.chipHeight
[animator animateWithTiming:timing.chipHeight
toLayer:_chipView.layer
withValues:@[ @([self chipCornerRadius]), @0 ]
keyPath:MDMKeyPathCornerRadius];

// Cross-fade the chip's contents.
[animator animateWithTraits:traits.chipContentOpacity
[animator animateWithTiming:timing.chipContentOpacity
toLayer:_collapsedContent.layer
withValues:@[ @1, @0 ]
keyPath:MDMKeyPathOpacity];
[animator animateWithTraits:traits.headerContentOpacity
[animator animateWithTiming:timing.headerContentOpacity
toLayer:_expandedContent.layer
withValues:@[ @0, @1 ]
keyPath:MDMKeyPathOpacity];

// Keeps the expandec content aligned to the bottom of the card by taking into consideration the
// extra height.
CGFloat excessTopMargin = chipFrame.size.height - headerFrame.size.height;
[animator animateWithTraits:traits.chipHeight
[animator animateWithTiming:timing.chipHeight
toLayer:_expandedContent.layer
withValues:@[ @(CGRectGetMidY([self expandedContentFrame]) + excessTopMargin),
@(CGRectGetMidY([self expandedContentFrame])) ]
Expand All @@ -99,7 +99,7 @@ - (void)didTap {
// Keeps the collapsed content aligned to its position on screen by taking into consideration the
// excess left margin.
CGFloat excessLeftMargin = chipFrame.origin.x - headerFrame.origin.x;
[animator animateWithTraits:traits.chipWidth
[animator animateWithTiming:timing.chipWidth
toLayer:_collapsedContent.layer
withValues:@[ @(CGRectGetMidX([self collapsedContentFrame])),
@(CGRectGetMidX([self collapsedContentFrame]) + excessLeftMargin) ]
Expand All @@ -108,11 +108,11 @@ - (void)didTap {
// Keeps the shape anchored to the bottom right of the chip.
CGRect shapeFrameInChip = [self shapeFrameInRect:chipFrame];
CGRect shapeFrameInHeader = [self shapeFrameInRect:headerFrame];
[animator animateWithTraits:traits.chipWidth
[animator animateWithTiming:timing.chipWidth
toLayer:_shapeView.layer
withValues:@[ @(CGRectGetMidX(shapeFrameInChip)), @(CGRectGetMidX(shapeFrameInHeader)) ]
keyPath:MDMKeyPathX];
[animator animateWithTraits:traits.chipHeight
[animator animateWithTiming:timing.chipHeight
toLayer:_shapeView.layer
withValues:@[ @(CGRectGetMidY(shapeFrameInChip)), @(CGRectGetMidY(shapeFrameInHeader)) ]
keyPath:MDMKeyPathY];
Expand Down
24 changes: 11 additions & 13 deletions examples/CalendarChipMotionSpec.h
Expand Up @@ -17,26 +17,24 @@
#import <Foundation/Foundation.h>
#import <MotionInterchange/MotionInterchange.h>

@protocol CalendarChipTiming <NSObject>
typedef struct CalendarChipTiming {
MDMMotionTiming chipWidth;
MDMMotionTiming chipHeight;
MDMMotionTiming chipY;

@property(nonatomic, strong, nonnull, readonly) MDMAnimationTraits *chipWidth;
@property(nonatomic, strong, nonnull, readonly) MDMAnimationTraits *chipHeight;
@property(nonatomic, strong, nonnull, readonly) MDMAnimationTraits *chipY;
MDMMotionTiming chipContentOpacity;
MDMMotionTiming headerContentOpacity;

@property(nonatomic, strong, nonnull, readonly) MDMAnimationTraits *chipContentOpacity;
@property(nonatomic, strong, nonnull, readonly) MDMAnimationTraits *headerContentOpacity;

@property(nonatomic, strong, nonnull, readonly) MDMAnimationTraits *navigationBarY;

@end
MDMMotionTiming navigationBarY;
} CalendarChipTiming;

@interface CalendarChipMotionSpec: NSObject

@property(nonatomic, class, strong, nonnull, readonly) id<CalendarChipTiming> expansion;
@property(nonatomic, class, strong, nonnull, readonly) id<CalendarChipTiming> collapse;
@property(nonatomic, class, readonly) CalendarChipTiming expansion;
@property(nonatomic, class, readonly) CalendarChipTiming collapse;

// This object is not meant to be instantiated.
- (nonnull instancetype)init NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

@end

126 changes: 50 additions & 76 deletions examples/CalendarChipMotionSpec.m
Expand Up @@ -16,84 +16,58 @@

#import "CalendarChipMotionSpec.h"

static id<MDMTimingCurve> StandardTimingCurve(void) {
return [CAMediaTimingFunction functionWithControlPoints:0.4f :0.0f :0.2f :1.0f];
}

static id<MDMTimingCurve> LinearTimingCurve(void) {
return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
}

@interface CalendarChipExpansionTiming: NSObject <CalendarChipTiming>
@end

@implementation CalendarChipExpansionTiming

- (MDMAnimationTraits *)chipWidth {
return [[MDMAnimationTraits alloc] initWithDelay:0.000 duration:0.285 timingCurve:StandardTimingCurve()];
}

- (MDMAnimationTraits *)chipHeight {
return [[MDMAnimationTraits alloc] initWithDelay:0.015 duration:0.360 timingCurve:StandardTimingCurve()];
}

- (MDMAnimationTraits *)chipY {
return [[MDMAnimationTraits alloc] initWithDelay:0.015 duration:0.360 timingCurve:StandardTimingCurve()];
}

- (MDMAnimationTraits *)chipContentOpacity {
return [[MDMAnimationTraits alloc] initWithDelay:0.000 duration:0.075 timingCurve:LinearTimingCurve()];
}

- (MDMAnimationTraits *)headerContentOpacity {
return [[MDMAnimationTraits alloc] initWithDelay:0.075 duration:0.150 timingCurve:LinearTimingCurve()];
}

- (MDMAnimationTraits *)navigationBarY {
return [[MDMAnimationTraits alloc] initWithDelay:0.015 duration:0.360 timingCurve:StandardTimingCurve()];
}

@end

@interface CalendarChipCollapseTiming: NSObject <CalendarChipTiming>
@end

@implementation CalendarChipCollapseTiming

- (MDMAnimationTraits *)chipWidth {
return [[MDMAnimationTraits alloc] initWithDelay:0.045 duration:0.330 timingCurve:StandardTimingCurve()];
}

- (MDMAnimationTraits *)chipHeight {
return [[MDMAnimationTraits alloc] initWithDelay:0.000 duration:0.330 timingCurve:StandardTimingCurve()];
}

- (MDMAnimationTraits *)chipY {
return [[MDMAnimationTraits alloc] initWithDelay:0.015 duration:0.330 timingCurve:StandardTimingCurve()];
}

- (MDMAnimationTraits *)chipContentOpacity {
return [[MDMAnimationTraits alloc] initWithDelay:0.150 duration:0.150 timingCurve:LinearTimingCurve()];
}

- (MDMAnimationTraits *)headerContentOpacity {
return [[MDMAnimationTraits alloc] initWithDelay:0.000 duration:0.075 timingCurve:LinearTimingCurve()];
}

- (MDMAnimationTraits *)navigationBarY {
return [[MDMAnimationTraits alloc] initWithDelay:0.045 duration:0.150 timingCurve:StandardTimingCurve()];
}

@end

@implementation CalendarChipMotionSpec

+ (id<CalendarChipTiming>)expansion {
return [[CalendarChipExpansionTiming alloc] init];
}

+ (id<CalendarChipTiming>)collapse {
return [[CalendarChipCollapseTiming alloc] init];
+ (MDMMotionCurve)eightyForty {
return MDMMotionCurveMakeBezier(0.4f, 0.0f, 0.2f, 1.0f);
}

+ (CalendarChipTiming)expansion {
MDMMotionCurve eightyForty = [self eightyForty];
return (CalendarChipTiming){
.chipWidth = {
.delay = 0.000, .duration = 0.285, .curve = eightyForty,
},
.chipHeight = {
.delay = 0.015, .duration = 0.360, .curve = eightyForty,
},
.chipY = {
.delay = 0.015, .duration = 0.360, .curve = eightyForty,
},
.chipContentOpacity = {
.delay = 0.000, .duration = 0.075, .curve = MDMLinearMotionCurve,
},
.headerContentOpacity = {
.delay = 0.075, .duration = 0.150, .curve = MDMLinearMotionCurve,
},
.navigationBarY = {
.delay = 0.015, .duration = 0.360, .curve = eightyForty,
},
};
}

+ (CalendarChipTiming)collapse {
MDMMotionCurve eightyForty = [self eightyForty];
return (CalendarChipTiming){
.chipWidth = {
.delay = 0.045, .duration = 0.330, .curve = eightyForty,
},
.chipHeight = {
.delay = 0.000, .duration = 0.330, .curve = eightyForty,
},
.chipY = {
.delay = 0.015, .duration = 0.330, .curve = eightyForty,
},
.chipContentOpacity = {
.delay = 0.150, .duration = 0.150, .curve = MDMLinearMotionCurve,
},
.headerContentOpacity = {
.delay = 0.000, .duration = 0.075, .curve = MDMLinearMotionCurve,
},
.navigationBarY = {
.delay = 0.045, .duration = 0.150, .curve = eightyForty,
}
};
}

@end
Expand Down
13 changes: 6 additions & 7 deletions examples/TapToBounceExample.swift
Expand Up @@ -40,22 +40,21 @@ class TapToBounceExampleViewController: UIViewController {
for: [.touchUpInside, .touchUpOutside, .touchDragExit])
}

let traits = MDMAnimationTraits(delay: 0,
duration: 0.5,
timingCurve: MDMSpringTimingCurve(mass: 1,
tension: 100,
friction: 10))
let timing = MotionTiming(delay: 0,
duration: 0.5,
curve: MotionCurveMakeSpring(mass: 1, tension: 100, friction: 10),
repetition: .init())

func didFocus(_ sender: UIButton) {
let animator = MotionAnimator()
animator.animate(with: traits) {
animator.animate(with: timing) {
sender.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
}
}

func didUnfocus(_ sender: UIButton) {
let animator = MotionAnimator()
animator.animate(with: traits) {
animator.animate(with: timing) {
sender.transform = .identity
}
}
Expand Down

0 comments on commit f55625d

Please sign in to comment.