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

Implement v2 APIs #22

merged 13 commits into from
Dec 4, 2017

Conversation

jverkoey
Copy link
Contributor

@jverkoey jverkoey commented Dec 1, 2017

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.

romoore
romoore previously requested changes Dec 3, 2017

const MDMAnimationTraits MDMAnimationTraitsSystemModalMovement = {
.duration = 0.500, .timingCurve = {
.type = MDMTimingCurveTypeSpring, .data = { 3, 1000, 500, 0 }
Copy link

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?

Copy link
Contributor Author

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?

Copy link

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.

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.

Ah, I had assumed you meant renaming the data parameter. I'll give these values const names in the scope here.

/**
The value will be instantly set with no animation.
*/
MDMTimingCurveTypeInstant,
Copy link

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.

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.

/**
The data values corresponding with this curve.
*/
CGFloat data[4];
Copy link

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?

Copy link
Contributor Author

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.

Copy link

Choose a reason for hiding this comment

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

Ack.

*/
// clang-format off
FOUNDATION_EXTERN
MDMTimingCurve MDMTimingCurveMakeBezier(CGFloat p1x, CGFloat p1y, CGFloat p2x, CGFloat p2y)
Copy link

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.

Copy link
Contributor Author

@jverkoey jverkoey Dec 3, 2017

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.

Copy link

Choose a reason for hiding this comment

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

Ack.

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 }
Copy link

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.

Named indices for the bezier traits curve's data array.
*/
typedef NS_ENUM(NSUInteger, MDMTimingCurveBezierDataIndex) {
MDMTimingCurveBezierDataIndexP1X,
Copy link

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.

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.

romoore
romoore previously approved these changes Dec 4, 2017
@jverkoey
Copy link
Contributor Author

jverkoey commented Dec 4, 2017

Based on discussion with @romoore offline and with #5 in mind, I'm going to use this API v2 opportunity to implement the new APIs as ObjC types so that we don't have to do so in a v3.

@jverkoey jverkoey changed the title Implement v2 APIs [WIP] Implement v2 APIs Dec 4, 2017
@jverkoey jverkoey changed the title [WIP] Implement v2 APIs Implement v2 APIs Dec 4, 2017
@jverkoey
Copy link
Contributor Author

jverkoey commented Dec 4, 2017

API is now Objective-C'ized.

@jverkoey jverkoey dismissed romoore’s stale review December 4, 2017 18:13

Needs re-review.

}

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.

@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.

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.

XCTAssertFalse(repetition.autoreverses)
}

func testInitializationWithNumberOfRepetitionsAndAutoreversed() {
Copy link

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?

Copy link
Contributor Author

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;
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.

@jverkoey jverkoey merged commit 3a28e22 into develop Dec 4, 2017
@jverkoey jverkoey deleted the v2 branch December 4, 2017 22:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants