-
Notifications
You must be signed in to change notification settings - Fork 14
Implement v2 APIs #22
Conversation
src/MDMAnimationTraits.m
Outdated
|
||
const MDMAnimationTraits MDMAnimationTraitsSystemModalMovement = { | ||
.duration = 0.500, .timingCurve = { | ||
.type = MDMTimingCurveTypeSpring, .data = { 3, 1000, 500, 0 } |
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/Follow-up: Naming the data?
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.
I'm not sure what or how we would name this - did you have something in mind?
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.
I don't. They just look like a series of NSInteger(uint32_t, int16_t, double?) values. I know they make a timing curve, but looking at the code I have no idea what they're doing.
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.
Ah, I had assumed you meant renaming the data
parameter. I'll give these values const names in the scope here.
src/MDMTimingCurve.h
Outdated
/** | ||
The value will be instantly set with no animation. | ||
*/ | ||
MDMTimingCurveTypeInstant, |
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 assign an explicit numeric value to each of these.
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.
src/MDMTimingCurve.h
Outdated
/** | ||
The data values corresponding with this curve. | ||
*/ | ||
CGFloat data[4]; |
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.
Why do all timing curves have 4*sizeof(CGFloat) worth of data? Should this not be a pointer to another type?
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.
Given that these are C-structs, a pointer to another type would be require an extra hurdle to jump over when initializing these values. In practice the timing curves supported by Core Animation only need four pieces of data so this array has been fairly sufficient.
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.
Ack.
src/MDMTimingCurve.h
Outdated
*/ | ||
// clang-format off | ||
FOUNDATION_EXTERN | ||
MDMTimingCurve MDMTimingCurveMakeBezier(CGFloat p1x, CGFloat p1y, CGFloat p2x, CGFloat p2y) |
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.
Why not a pair of CGPoint? Why 4 explicit CGFloat? It seems that if they represent 2 points, it's best to use CGPoint to provide additional context. Also consider naming "p2x, p2y, p3x, p3y" to match the method documentation.
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.
This is in keeping consistent with the CAMediaTimingFunction API.
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.
Ack.
src/MDMTimingCurve.m
Outdated
MDMMotionCurve MDMMotionCurveMakeBezier(CGFloat p1x, CGFloat p1y, CGFloat p2x, CGFloat p2y) { | ||
return _MDMBezier(p1x, p1y, p2x, p2y); | ||
const MDMTimingCurve MDMTimingCurveLinear = { | ||
.type = MDMTimingCurveTypeBezier, .data = { 0, 0, 1, 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.
Same request for named structures if possible later.
src/MDMTimingCurve.h
Outdated
Named indices for the bezier traits curve's data array. | ||
*/ | ||
typedef NS_ENUM(NSUInteger, MDMTimingCurveBezierDataIndex) { | ||
MDMTimingCurveBezierDataIndexP1X, |
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 provide explicit numeric values for these and below. This seems especially valuable since they will function as indices into zero-based arrays.
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.
API is now Objective-C'ized. |
scripts/v1_to_v2.sh
Outdated
} | ||
|
||
replace_all() { | ||
replace_objc $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.
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.
scripts/v1_to_v2.sh
Outdated
replace_swift $1 | ||
} | ||
|
||
# replace_all "s/MotionCurveMakeSpring(mass/TimingCurve(springWithMass/g" |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/MDMAnimationTraits.h
Outdated
@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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/MDMAnimationTraits.h
Outdated
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 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?
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.
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 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?
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.
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.
XCTAssertFalse(repetition.autoreverses) | ||
} | ||
|
||
func testInitializationWithNumberOfRepetitionsAndAutoreversed() { |
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.
The name says "number of repetitions" but the code says duration. Wrong name?
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.
Fixed.
@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 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:
- (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 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.
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.
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.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.