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

Implement v2 APIs #22

Merged
merged 13 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
objects = {

/* Begin PBXBuildFile section */
660248AE1FD1EE78004C0147 /* MDMSpringTimingCurve.swift in Sources */ = {isa = PBXBuildFile; fileRef = 660248AC1FD1EE78004C0147 /* MDMSpringTimingCurve.swift */; };
6619E1D91FA0ED0300F3AB25 /* MDMModalMovementTimingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6619E1D81FA0ED0300F3AB25 /* MDMModalMovementTimingTests.m */; };
663ED7C51EDF1F0C0096B2A9 /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 663ED7C01EDF1F0C0096B2A9 /* ExampleViewController.swift */; };
663ED7C61EDF1F0C0096B2A9 /* ExampleViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 663ED7C11EDF1F0C0096B2A9 /* ExampleViews.swift */; };
663ED7C71EDF1F0C0096B2A9 /* HexColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 663ED7C21EDF1F0C0096B2A9 /* HexColor.swift */; };
663ED7C81EDF1F0C0096B2A9 /* Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 663ED7C31EDF1F0C0096B2A9 /* Layout.swift */; };
663ED7C91EDF1F0C0096B2A9 /* ModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 663ED7C41EDF1F0C0096B2A9 /* ModalViewController.swift */; };
663ED8011EE628BA0096B2A9 /* MDMMotionCurveTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 663ED8001EE628BA0096B2A9 /* MDMMotionCurveTests.swift */; };
663ED8031EE6299A0096B2A9 /* MDMMotionCurveTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 663ED8021EE6299A0096B2A9 /* MDMMotionCurveTests.m */; };
664C8C531FD5A555004ED471 /* CAMediaTimingFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664C8C521FD5A555004ED471 /* CAMediaTimingFunctionTests.swift */; };
664C8C551FD5A7B7004ED471 /* MDMRepetitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664C8C541FD5A7B7004ED471 /* MDMRepetitionTests.swift */; };
664C8C571FD5A831004ED471 /* MDMRepetitionOverTimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664C8C561FD5A831004ED471 /* MDMRepetitionOverTimeTests.swift */; };
664C8C591FD5A8AC004ED471 /* MDMAnimationTraitsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664C8C581FD5A8AC004ED471 /* MDMAnimationTraitsTests.swift */; };
666FAA841D384A6B000363DA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666FAA831D384A6B000363DA /* AppDelegate.swift */; };
666FAA8B1D384A6B000363DA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 666FAA8A1D384A6B000363DA /* Assets.xcassets */; };
666FAA8E1D384A6B000363DA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 666FAA8C1D384A6B000363DA /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -47,14 +50,17 @@
09CEA5DEA01BA723D08D84E6 /* Pods-UnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UnitTests.release.xcconfig"; path = "../../../Pods/Target Support Files/Pods-UnitTests/Pods-UnitTests.release.xcconfig"; sourceTree = "<group>"; };
2DE76D4D35953D836F578CDE /* Pods-MotionInterchangeCatalog.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MotionInterchangeCatalog.debug.xcconfig"; path = "../../../Pods/Target Support Files/Pods-MotionInterchangeCatalog/Pods-MotionInterchangeCatalog.debug.xcconfig"; sourceTree = "<group>"; };
4AAB8EBB088513D48896641A /* Pods-MotionInterchangeCatalog.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MotionInterchangeCatalog.release.xcconfig"; path = "../../../Pods/Target Support Files/Pods-MotionInterchangeCatalog/Pods-MotionInterchangeCatalog.release.xcconfig"; sourceTree = "<group>"; };
660248AC1FD1EE78004C0147 /* MDMSpringTimingCurve.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MDMSpringTimingCurve.swift; sourceTree = "<group>"; };
6619E1D81FA0ED0300F3AB25 /* MDMModalMovementTimingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MDMModalMovementTimingTests.m; sourceTree = "<group>"; };
663ED7C01EDF1F0C0096B2A9 /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
663ED7C11EDF1F0C0096B2A9 /* ExampleViews.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViews.swift; sourceTree = "<group>"; };
663ED7C21EDF1F0C0096B2A9 /* HexColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HexColor.swift; sourceTree = "<group>"; };
663ED7C31EDF1F0C0096B2A9 /* Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Layout.swift; sourceTree = "<group>"; };
663ED7C41EDF1F0C0096B2A9 /* ModalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalViewController.swift; sourceTree = "<group>"; };
663ED8001EE628BA0096B2A9 /* MDMMotionCurveTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MDMMotionCurveTests.swift; sourceTree = "<group>"; };
663ED8021EE6299A0096B2A9 /* MDMMotionCurveTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MDMMotionCurveTests.m; sourceTree = "<group>"; };
664C8C521FD5A555004ED471 /* CAMediaTimingFunctionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CAMediaTimingFunctionTests.swift; sourceTree = "<group>"; };
664C8C541FD5A7B7004ED471 /* MDMRepetitionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MDMRepetitionTests.swift; sourceTree = "<group>"; };
664C8C561FD5A831004ED471 /* MDMRepetitionOverTimeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MDMRepetitionOverTimeTests.swift; sourceTree = "<group>"; };
664C8C581FD5A8AC004ED471 /* MDMAnimationTraitsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MDMAnimationTraitsTests.swift; sourceTree = "<group>"; };
666FAA801D384A6B000363DA /* MotionInterchangeCatalog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MotionInterchangeCatalog.app; sourceTree = BUILT_PRODUCTS_DIR; };
666FAA831D384A6B000363DA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = Catalog/AppDelegate.swift; sourceTree = "<group>"; };
666FAA8A1D384A6B000363DA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,9 +168,12 @@
666FAA971D384A6B000363DA /* tests */ = {
isa = PBXGroup;
children = (
663ED8001EE628BA0096B2A9 /* MDMMotionCurveTests.swift */,
663ED8021EE6299A0096B2A9 /* MDMMotionCurveTests.m */,
664C8C521FD5A555004ED471 /* CAMediaTimingFunctionTests.swift */,
664C8C581FD5A8AC004ED471 /* MDMAnimationTraitsTests.swift */,
6619E1D81FA0ED0300F3AB25 /* MDMModalMovementTimingTests.m */,
664C8C541FD5A7B7004ED471 /* MDMRepetitionTests.swift */,
664C8C561FD5A831004ED471 /* MDMRepetitionOverTimeTests.swift */,
660248AC1FD1EE78004C0147 /* MDMSpringTimingCurve.swift */,
);
name = tests;
path = ../../../tests/unit;
Expand Down Expand Up @@ -478,9 +487,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
663ED8031EE6299A0096B2A9 /* MDMMotionCurveTests.m in Sources */,
663ED8011EE628BA0096B2A9 /* MDMMotionCurveTests.swift in Sources */,
664C8C531FD5A555004ED471 /* CAMediaTimingFunctionTests.swift in Sources */,
660248AE1FD1EE78004C0147 /* MDMSpringTimingCurve.swift in Sources */,
6619E1D91FA0ED0300F3AB25 /* MDMModalMovementTimingTests.m in Sources */,
664C8C571FD5A831004ED471 /* MDMRepetitionOverTimeTests.swift in Sources */,
664C8C591FD5A8AC004ED471 /* MDMAnimationTraitsTests.swift in Sources */,
664C8C551FD5A7B7004ED471 /* MDMRepetitionTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
51 changes: 51 additions & 0 deletions scripts/v1_to_v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
#
# 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.

# Migration script from v1 to v2 interchange APIs.

if [ "$#" -ne 1 ]; then
echo "Usage: $(basename $0) <path>"
exit 1
fi

search_path="$1"

replace_objc() {
find "$search_path" -type f -name "*.h" | xargs sed -i '' "$1"
find "$search_path" -type f -name "*.m" | xargs sed -i '' "$1"
}

replace_swift() {
find "$search_path" -type f -name "*.swift" | xargs sed -i '' "$1"
}

replace_all() {
replace_objc $1
Copy link

Choose a reason for hiding this comment

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

Please place quotes around the expanding variable so that paths with spaces (or special characters) won't break. "$1"

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.

replace_swift $1
}

# replace_all "s/MotionCurveMakeSpring(mass/TimingCurve(springWithMass/g"
Copy link

Choose a reason for hiding this comment

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

I would suggest either grouping all the commented-out replacements at the bottom (with a comment) or remove them entirely.

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.

# replace_all "s/TimingCurveMakeBezier(p1x/TimingCurve(bezierWithP1x/g"
# replace_all "s/MDMLinearTimingCurve/MDMTimingCurveLinear/g"
# replace_all "s/MDMModalMovementTiming/MDMAnimationTraitsSystemModalMovement/g"
replace_all "s/timing.curve/traits.timingCurve/g"
replace_all "s/traits.curve/traits.timingCurve/g"
# replace_all "s/\.curve/.timingCurve/g"
# replace_all "s/MotionCurve/TimingCurve/g"
# replace_all "s/MotionRepetition/RepetitionTraits/g"
# replace_all "s/MotionTiming timing/AnimationTraits traits/g"
replace_objc "s/MDMMotionTiming/MDMAnimationTraits */g"
replace_swift "s/MotionTiming/MDMAnimationTraits/g"
44 changes: 44 additions & 0 deletions src/CAMediaTimingFunction+MDMTimingCurve.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
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 <QuartzCore/QuartzCore.h>
#import <Foundation/Foundation.h>

#import "MDMTimingCurve.h"

// A CAMediaTimingFunction is a timing curve - we simply define its conformity to our protocol here.
@interface CAMediaTimingFunction () <MDMTimingCurve>
@end

@interface CAMediaTimingFunction (MotionInterchangeExtension)

/**
Returns a instance of the timing function with its control points reversed.
*/
- (nonnull CAMediaTimingFunction *)mdm_reversed;

/**
Returns the first control point of the timing function.
*/
@property(nonatomic, assign, readonly) CGPoint mdm_point1;

/**
Returns the second control point of the timing function.
*/
@property(nonatomic, assign, readonly) CGPoint mdm_point2;

@end

49 changes: 49 additions & 0 deletions src/CAMediaTimingFunction+MDMTimingCurve.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
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 "CAMediaTimingFunction+MDMTimingCurve.h"

@implementation CAMediaTimingFunction (MotionInterchangeExtension)

- (CAMediaTimingFunction *)mdm_reversed {
float pt1[2];
float pt2[2];
[self getControlPointAtIndex:1 values:pt1];
[self getControlPointAtIndex:2 values:pt2];

float reversedPt1[2];
float reversedPt2[2];
reversedPt1[0] = 1 - pt2[0];
reversedPt1[1] = 1 - pt2[1];
reversedPt2[0] = 1 - pt1[0];
reversedPt2[1] = 1 - pt1[1];
return [CAMediaTimingFunction functionWithControlPoints:reversedPt1[0] :reversedPt1[1]
:reversedPt2[0] :reversedPt2[1]];
}

- (CGPoint)mdm_point1 {
float point[2];
[self getControlPointAtIndex:1 values:point];
return CGPointMake(point[0], point[1]);
}

- (CGPoint)mdm_point2 {
float point[2];
[self getControlPointAtIndex:2 values:point];
return CGPointMake(point[0], point[1]);
}

@end
114 changes: 114 additions & 0 deletions src/MDMAnimationTraits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
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 <CoreGraphics/CoreGraphics.h>
#import <Foundation/Foundation.h>

#import "MDMRepetitionTraits.h"
#import "MDMTimingCurve.h"

/**
A generic representation of animation traits.
*/
@interface MDMAnimationTraits: NSObject

/**
Initializes the instance with the provided duration and default iOS ease in/out cubic bezier.
Copy link

Choose a reason for hiding this comment

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

Nit: Consider referencing the actual constant function.

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.


@param duration The animation will occur over this length of time, in seconds.
*/
- (nonnull instancetype)initWithDuration:(NSTimeInterval)duration;

/**
Initializes the instance with the provided duration, delay, and default iOS ease in/out cubic
bezier.

@param delay The amount of time, in seconds, to wait before starting the animation.
Copy link

Choose a reason for hiding this comment

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

Is any non-positive delay treated as "instantaneous" or would the animation be reversed?

Copy link
Contributor Author

@jverkoey jverkoey Dec 4, 2017

Choose a reason for hiding this comment

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

Negative delay would shift the animation backward in time. E.g if animating linearly from 0 to 1 over 10 seconds, a delay of -5 would start the animation at 0.5 and animate for 5 seconds before completing.

Copy link

Choose a reason for hiding this comment

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

And a negative duration would animate backwards until the duration is met?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears that Core Animation will default to a duration of 0.25 when the duration is <= 0. Wonderful! material-motion/motion-animator-objc#87 filed to track.

@param duration The animation will occur over this length of time, in seconds, after the delay time
has passed.
*/
- (nonnull instancetype)initWithDelay:(NSTimeInterval)delay duration:(NSTimeInterval)duration;
Copy link

Choose a reason for hiding this comment

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

Nit: This should probably be "initWithDuration:delay:" to match the convenience constructor above. Same for the two below.

Copy link
Contributor Author

@jverkoey jverkoey Dec 4, 2017

Choose a reason for hiding this comment

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

Have flip-flopped on this. Conceptually the delay happens before the duration, so I was attempting to make it easier to scan and understand blocks of animation traits. I was finding it harder to read the blocks when delay was the second argument. For example:

- (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()];
}

Copy link

Choose a reason for hiding this comment

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

That makes sense. Not a blocking issue, just jumped out at me when I was reading.


/**
Initializes the instance with the provided duration, delay, and timing curve.

@param delay The amount of time, in seconds, to wait before starting the animation.
@param duration The animation will occur over this length of time, in seconds, after the delay time
has passed.
@param timingCurve If provided, defines the acceleration timing for the animation. If nil, the
animation will be treated as instant and the duration/delay will be ignored.
*/
- (nonnull instancetype)initWithDelay:(NSTimeInterval)delay
duration:(NSTimeInterval)duration
timingCurve:(nullable id<MDMTimingCurve>)timingCurve;

/**
Initializes an animation trait with the provided timing curve, duration, delay, and repetition.

@param duration The animation will occur over this length of time, in seconds, after the delay time
has passed.
@param delay The amount of time, in seconds, to wait before starting the animation.
@param timingCurve If provided, defines the acceleration timing for the animation. If nil, the
animation will be treated as instant and the duration/delay will be ignored.
@param repetition The repetition traits of the animation. Most often an instance of MDMRepetition
or MDMRepetitionOverTime. If nil, the animation will not repeat.
*/
- (nonnull instancetype)initWithDelay:(NSTimeInterval)delay
duration:(NSTimeInterval)duration
timingCurve:(nullable id<MDMTimingCurve>)timingCurve
repetition:(nullable id<MDMRepetitionTraits>)repetition
NS_DESIGNATED_INITIALIZER;

#pragma mark - Traits

/**
The amount of time, in seconds, before this animation's value interpolation should begin.
*/
@property(nonatomic, assign, readonly) NSTimeInterval delay;

/**
The amount of time, in seconds, over which this animation should interpolate between its values.
*/
@property(nonatomic, assign, readonly) NSTimeInterval duration;

/**
The velocity and acceleration of the animation over time.
*/
@property(nonatomic, strong, nullable, readonly) id<MDMTimingCurve> timingCurve;

/**
The repetition characteristics of the animation.
*/
@property(nonatomic, strong, nullable, readonly) id<MDMRepetitionTraits> repetition;

#pragma mark - Unavailable

/**
Unavailable.
*/
- (nonnull instancetype)init NS_UNAVAILABLE;

@end

@interface MDMAnimationTraits (SystemTraits)

/**
Animation traits for an iOS modal presentation slide animation.
*/
@property(nonatomic, class, strong, nonnull, readonly) MDMAnimationTraits *systemModalMovement;

@end

Loading