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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0f6bf48
Add v2 apis.
a334d4d
Add repetition renaming.
1865087
Fix more tests.
6630061
Delete unused header.
55001b4
More to script.
151d00c
Review feedback.
b0c260b
API name.
8c32394
Docs.
4aceb00
Implement the APIs in Objective-C. Increase testing coverage.
a400a25
Reordering.
771d712
Fix tests.
c4a4cc2
Quotes.
6898bac
Review feedback.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.