This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In short: this PR drops the redundant "motion" prefix on various types and aligns naming with system terminology where possible and re-implements the APIs as Objective-C APIs, closing #5. | Old API | New API | Rationale | |:------- |:-------- |:-----------| | MotionTiming | AnimationTraits | This structure is intended to describe animations only, not motion in general. | | MotionCurve | TimingCurve | This brings the API name closer to the similarly-purposed `CAMediaTimingFunction`. MotionCurve could also be easily confused with motion through x/y space rather than through time (e.g. ArcMove), which will be problematic as we start defining paths of motion through space. | | MotionRepetition | RepetitionTraits | This aligns the naming with AnimationTraits. | All prior APIs have been deleted, including the macro-based APIs and any active deprecations. This is a major change and will bump the release to v2. A migration script has been included to ease migration of existing code.
- Loading branch information
Showing
27 changed files
with
1,013 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/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" | ||
replace_swift "$1" | ||
} | ||
|
||
replace_all "s/timing.curve/traits.timingCurve/g" | ||
replace_all "s/traits.curve/traits.timingCurve/g" | ||
replace_objc "s/MDMMotionTiming/MDMAnimationTraits */g" | ||
replace_swift "s/MotionTiming/MDMAnimationTraits/g" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
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 kCAMediaTimingFunctionEaseInEaseOut timing | ||
curve. | ||
@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 | ||
kCAMediaTimingFunctionEaseInEaseOut 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. | ||
*/ | ||
- (nonnull instancetype)initWithDelay:(NSTimeInterval)delay duration:(NSTimeInterval)duration; | ||
|
||
/** | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
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 "MDMAnimationTraits.h" | ||
|
||
#import "CAMediaTimingFunction+MDMTimingCurve.h" | ||
#import "MDMSpringTimingCurve.h" | ||
|
||
@implementation MDMAnimationTraits | ||
|
||
- (instancetype)init { | ||
[self doesNotRecognizeSelector:_cmd]; | ||
return nil; | ||
} | ||
|
||
- (nonnull instancetype)initWithDuration:(NSTimeInterval)duration { | ||
return [self initWithDelay:0 duration:duration]; | ||
} | ||
|
||
- (instancetype)initWithDelay:(NSTimeInterval)delay duration:(NSTimeInterval)duration { | ||
CAMediaTimingFunction *easeInOut = | ||
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | ||
return [self initWithDelay:delay duration:duration timingCurve:easeInOut]; | ||
} | ||
|
||
- (instancetype)initWithDelay:(NSTimeInterval)delay | ||
duration:(NSTimeInterval)duration | ||
timingCurve:(id<MDMTimingCurve>)timingCurve { | ||
return [self initWithDelay:delay duration:duration timingCurve:timingCurve repetition:nil]; | ||
} | ||
|
||
- (instancetype)initWithDelay:(NSTimeInterval)delay | ||
duration:(NSTimeInterval)duration | ||
timingCurve:(id<MDMTimingCurve>)timingCurve | ||
repetition:(id<MDMRepetitionTraits>)repetition { | ||
self = [super init]; | ||
if (self) { | ||
_duration = duration; | ||
_delay = delay; | ||
_timingCurve = timingCurve; | ||
_repetition = repetition; | ||
} | ||
return self; | ||
} | ||
|
||
@end | ||
|
||
@implementation MDMAnimationTraits (SystemTraits) | ||
|
||
+ (MDMAnimationTraits *)systemModalMovement { | ||
MDMSpringTimingCurve *timingCurve = [[MDMSpringTimingCurve alloc] initWithMass:3 | ||
tension:1000 | ||
friction:500]; | ||
return [[MDMAnimationTraits alloc] initWithDelay:0 duration:0.500 timingCurve:timingCurve]; | ||
} | ||
|
||
@end | ||
|
Oops, something went wrong.