-
Notifications
You must be signed in to change notification settings - Fork 14
Changes from 11 commits
0f6bf48
a334d4d
1865087
6630061
55001b4
151d00c
b0c260b
8c32394
4aceb00
a400a25
771d712
c4a4cc2
6898bac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
replace_swift $1 | ||
} | ||
|
||
# replace_all "s/MotionCurveMakeSpring(mass/TimingCurve(springWithMass/g" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" |
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 | ||
|
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 |
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Consider referencing the actual constant function. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And a negative duration would animate backwards until the duration is met? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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()];
} There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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.
Please place quotes around the expanding variable so that paths with spaces (or special characters) won't break.
"$1"
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.
Done.