This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a partial revert of commit 3a28e22. This will allow us to gradually migrate clients to the new v2 APIs without immediately introducing a breaking change.
- Loading branch information
Showing
7 changed files
with
509 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
/* | ||
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 <QuartzCore/QuartzCore.h> | ||
|
||
/** | ||
The possible kinds of motion curves that can be used to describe an animation. | ||
*/ | ||
typedef NS_ENUM(NSUInteger, MDMMotionCurveType) { | ||
/** | ||
The value will be instantly set with no animation. | ||
*/ | ||
MDMMotionCurveTypeInstant, | ||
|
||
/** | ||
The value will be animated using a cubic bezier curve to model its velocity. | ||
*/ | ||
MDMMotionCurveTypeBezier, | ||
|
||
/** | ||
The value will be animated using a spring simulation. | ||
A spring will treat the duration property of the motion timing as a suggestion and may choose to | ||
ignore it altogether. | ||
*/ | ||
MDMMotionCurveTypeSpring, | ||
|
||
/** | ||
The default curve will be used. | ||
*/ | ||
MDMMotionCurveTypeDefault __deprecated_enum_msg("Use MDMMotionCurveTypeBezier instead."), | ||
|
||
} NS_SWIFT_NAME(MotionCurveType); | ||
|
||
/** | ||
A generalized representation of a motion curve. | ||
*/ | ||
struct MDMMotionCurve { | ||
/** | ||
The type defines how to interpret the data values. | ||
*/ | ||
MDMMotionCurveType type; | ||
|
||
/** | ||
The data values corresponding with this curve. | ||
*/ | ||
CGFloat data[4]; | ||
} NS_SWIFT_NAME(MotionCurve); | ||
typedef struct MDMMotionCurve MDMMotionCurve; | ||
|
||
/** | ||
Creates a bezier motion curve with the provided control points. | ||
A cubic bezier has four control points in total. We assume that the first control point is 0, 0 and | ||
the last control point is 1, 1. This method requires that you provide the second and third control | ||
points. | ||
See the documentation for CAMediaTimingFunction for more information. | ||
*/ | ||
// clang-format off | ||
FOUNDATION_EXTERN | ||
MDMMotionCurve MDMMotionCurveMakeBezier(CGFloat p1x, CGFloat p1y, CGFloat p2x, CGFloat p2y) | ||
NS_SWIFT_NAME(MotionCurveMakeBezier(p1x:p1y:p2x:p2y:)); | ||
// clang-format on | ||
|
||
// clang-format off | ||
FOUNDATION_EXTERN | ||
MDMMotionCurve MDMMotionCurveFromTimingFunction(CAMediaTimingFunction * _Nonnull timingFunction) | ||
NS_SWIFT_NAME(MotionCurve(fromTimingFunction:)); | ||
// clang-format on | ||
|
||
/** | ||
Creates a spring curve with the provided configuration. | ||
Tension and friction map to Core Animation's stiffness and damping, respectively. | ||
See the documentation for CASpringAnimation for more information. | ||
*/ | ||
// clang-format off | ||
FOUNDATION_EXTERN MDMMotionCurve MDMMotionCurveMakeSpring(CGFloat mass, | ||
CGFloat tension, | ||
CGFloat friction) | ||
NS_SWIFT_NAME(MotionCurveMakeSpring(mass:tension:friction:)); | ||
// clang-format on | ||
|
||
/** | ||
Creates a spring curve with the provided configuration. | ||
Tension and friction map to Core Animation's stiffness and damping, respectively. | ||
See the documentation for CASpringAnimation for more information. | ||
*/ | ||
// clang-format off | ||
FOUNDATION_EXTERN | ||
MDMMotionCurve MDMMotionCurveMakeSpringWithInitialVelocity(CGFloat mass, | ||
CGFloat tension, | ||
CGFloat friction, | ||
CGFloat initialVelocity) | ||
NS_SWIFT_NAME(MotionCurveMakeSpring(mass:tension:friction:initialVelocity:)); | ||
// clang-format on | ||
|
||
/** | ||
For cubic bezier curves, returns a reversed cubic bezier curve. For all other curve types, a copy | ||
of the original curve is returned. | ||
*/ | ||
// clang-format off | ||
FOUNDATION_EXTERN MDMMotionCurve MDMMotionCurveReversedBezier(MDMMotionCurve motionCurve) | ||
NS_SWIFT_NAME(MotionCurveReversedBezier(fromMotionCurve:)); | ||
// clang-format on | ||
|
||
/** | ||
Named indices for the bezier motion curve's data array. | ||
*/ | ||
typedef NS_ENUM(NSUInteger, MDMBezierMotionCurveDataIndex) { | ||
MDMBezierMotionCurveDataIndexP1X, | ||
MDMBezierMotionCurveDataIndexP1Y, | ||
MDMBezierMotionCurveDataIndexP2X, | ||
MDMBezierMotionCurveDataIndexP2Y | ||
} NS_SWIFT_NAME(BezierMotionCurveDataIndex); | ||
|
||
/** | ||
Named indices for the spring motion curve's data array. | ||
*/ | ||
typedef NS_ENUM(NSUInteger, MDMSpringMotionCurveDataIndex) { | ||
MDMSpringMotionCurveDataIndexMass, | ||
MDMSpringMotionCurveDataIndexTension, | ||
MDMSpringMotionCurveDataIndexFriction, | ||
|
||
/** | ||
The initial velocity of the animation. | ||
A value of zero indicates no initial velocity. | ||
A positive value indicates movement toward the destination. | ||
A negative value indicates movement away from the destination. | ||
The value's units are dependent on the context and the value being animated. | ||
*/ | ||
MDMSpringMotionCurveDataIndexInitialVelocity | ||
} NS_SWIFT_NAME(SpringMotionCurveDataIndex); | ||
|
||
// Objective-C-specific macros | ||
|
||
#define _MDMBezier(p1x, p1y, p2x, p2y) \ | ||
((MDMMotionCurve) { \ | ||
.type = MDMMotionCurveTypeBezier, \ | ||
.data = { p1x, \ | ||
p1y, \ | ||
p2x, \ | ||
p2y } \ | ||
}) | ||
|
||
#define _MDMSpring(mass, tension, friction) \ | ||
((MDMMotionCurve) { \ | ||
.type = MDMMotionCurveTypeSpring, \ | ||
.data = { mass, \ | ||
tension, \ | ||
friction } \ | ||
}) | ||
|
||
#define _MDMSpringWithInitialVelocity(mass, tension, friction, initialVelocity) \ | ||
((MDMMotionCurve) { \ | ||
.type = MDMMotionCurveTypeSpring, \ | ||
.data = { mass, \ | ||
tension, \ | ||
friction, \ | ||
initialVelocity } \ | ||
}) | ||
|
||
/** | ||
A linear bezier motion curve. | ||
*/ | ||
#define MDMLinearMotionCurve _MDMBezier(0, 0, 1, 1) | ||
|
||
/** | ||
Timing information for an iOS modal presentation slide animation. | ||
*/ | ||
#define MDMModalMovementTiming { \ | ||
.delay = 0.000, .duration = 0.500, .curve = _MDMSpring(3, 1000, 500) \ | ||
} |
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,51 @@ | ||
/* | ||
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 "MDMMotionCurve.h" | ||
|
||
MDMMotionCurve MDMMotionCurveMakeBezier(CGFloat p1x, CGFloat p1y, CGFloat p2x, CGFloat p2y) { | ||
return _MDMBezier(p1x, p1y, p2x, p2y); | ||
} | ||
|
||
MDMMotionCurve MDMMotionCurveMakeSpring(CGFloat mass, CGFloat tension, CGFloat friction) { | ||
return MDMMotionCurveMakeSpringWithInitialVelocity(mass, tension, friction, 0); | ||
} | ||
|
||
MDMMotionCurve MDMMotionCurveMakeSpringWithInitialVelocity(CGFloat mass, | ||
CGFloat tension, | ||
CGFloat friction, | ||
CGFloat initialVelocity) { | ||
return _MDMSpringWithInitialVelocity(mass, tension, friction, initialVelocity); | ||
} | ||
|
||
MDMMotionCurve MDMMotionCurveFromTimingFunction(CAMediaTimingFunction *timingFunction) { | ||
float pt1[2]; | ||
float pt2[2]; | ||
[timingFunction getControlPointAtIndex:1 values:pt1]; | ||
[timingFunction getControlPointAtIndex:2 values:pt2]; | ||
return MDMMotionCurveMakeBezier(pt1[0], pt1[1], pt2[0], pt2[1]); | ||
} | ||
|
||
MDMMotionCurve MDMMotionCurveReversedBezier(MDMMotionCurve motionCurve) { | ||
MDMMotionCurve reversed = motionCurve; | ||
if (motionCurve.type == MDMMotionCurveTypeBezier) { | ||
reversed.data[0] = 1 - motionCurve.data[2]; | ||
reversed.data[1] = 1 - motionCurve.data[3]; | ||
reversed.data[2] = 1 - motionCurve.data[0]; | ||
reversed.data[3] = 1 - motionCurve.data[1]; | ||
} | ||
return reversed; | ||
} |
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,70 @@ | ||
/* | ||
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> | ||
|
||
/** | ||
The possible kinds of repetition that can be used to describe an animation. | ||
*/ | ||
typedef NS_ENUM(NSUInteger, MDMMotionRepetitionType) { | ||
/** | ||
The animation will be not be repeated. | ||
*/ | ||
MDMMotionRepetitionTypeNone, | ||
|
||
/** | ||
The animation will be repeated a given number of times. | ||
*/ | ||
MDMMotionRepetitionTypeCount, | ||
|
||
/** | ||
The animation will be repeated for a given number of seconds. | ||
*/ | ||
MDMMotionRepetitionTypeDuration, | ||
|
||
} NS_SWIFT_NAME(MotionReptitionType); | ||
|
||
/** | ||
A generalized representation of a motion curve. | ||
*/ | ||
struct MDMMotionRepetition { | ||
/** | ||
The type defines how to interpret the amount. | ||
*/ | ||
MDMMotionRepetitionType type; | ||
|
||
/** | ||
The amount of repetition. | ||
*/ | ||
double amount; | ||
|
||
/** | ||
Whether the animation should animate backwards after animating forwards. | ||
*/ | ||
BOOL autoreverses; | ||
|
||
} NS_SWIFT_NAME(MotionRepetition); | ||
typedef struct MDMMotionRepetition MDMMotionRepetition; | ||
|
||
// Objective-C-specific macros | ||
|
||
#define _MDMNoRepetition \ | ||
(MDMMotionRepetition) { \ | ||
.type = MDMMotionRepetitionTypeNone, \ | ||
.amount = 0, \ | ||
.autoreverses = false \ | ||
} |
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,48 @@ | ||
/* | ||
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 "MDMMotionCurve.h" | ||
#import "MDMMotionRepetition.h" | ||
|
||
/** | ||
A representation of timing for an animation. | ||
*/ | ||
struct MDMMotionTiming { | ||
/** | ||
The amount of time, in seconds, before this animation's value interpolation should begin. | ||
*/ | ||
CFTimeInterval delay; | ||
|
||
/** | ||
The amount of time, in seconds, over which this animation should interpolate between its values. | ||
*/ | ||
CFTimeInterval duration; | ||
|
||
/** | ||
The velocity and acceleration of the animation over time. | ||
*/ | ||
MDMMotionCurve curve; | ||
|
||
/** | ||
The repetition characteristics of the animation. | ||
*/ | ||
MDMMotionRepetition repetition; | ||
|
||
} NS_SWIFT_NAME(MotionTiming); | ||
typedef struct MDMMotionTiming MDMMotionTiming; |
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
Oops, something went wrong.