Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iOS): enable dampingRatio and springVelocity #10564

Merged
merged 22 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions apidoc/Titanium/UI/Animation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ properties:
constants: Titanium.UI.ANIMATION_CURVE_*
platforms: [android, iphone, ipad]
since: { android: "8.0.0", iphone: "0.9", ipad: "0.9" }

- name: dampingRatio
summary: |
The damping ratio for the spring animation as it approaches its quiescent state.
description: |
Use a value between 0 and 1. For a smoother deceleration use values closer to 1.
To increase oscillation use value closer to 0.
type: Number
platforms: [iphone, ipad]
since: "8.1.0"

Copy link
Collaborator

Choose a reason for hiding this comment

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

since: "8.1.0"

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! thanks!

- name: delay
summary: Delay, in milliseconds before starting the animation.
Expand Down Expand Up @@ -142,6 +152,17 @@ properties:
- name: right
summary: Value of the `right` property at the end of the animation.
type: Number

- name: springVelocity
summary: The initial spring velocity.
description: |
For smooth start to the animation, match this value to the velocity of view as it was prior to attachment.
A value of 1 corresponds to the total animation distance traversed in one second.
For example, if the total animation distance is 200 points and you want the start of the
animation to match a view velocity of 100 pt/s, use a value of 0.5.
type: Number
platforms: [iphone, ipad]
since: "8.1.0"

- name: top
summary: Value of the `top` property at the end of the animation.
Expand Down
4 changes: 4 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
NSNumber *transition;
TiViewProxy *view;
TiViewProxy *animatedViewProxy;
NSNumber *dampingRatio;
NSNumber *springVelocity;

// this is a temporary function passed in
ListenerEntry *callback;
Expand Down Expand Up @@ -133,6 +135,8 @@
@property (nonatomic, retain, readwrite) TiProxy *transform;
@property (nonatomic, retain, readwrite) NSNumber *transition;
@property (nonatomic, retain, readwrite) TiProxy *view;
@property (nonatomic, retain, readwrite) NSNumber *dampingRatio;
@property (nonatomic, retain, readwrite) NSNumber *springVelocity;

+ (TiAnimation *)animationFromArg:(id)args context:(id<TiEvaluator>)context create:(BOOL)yn;

Expand Down
30 changes: 24 additions & 6 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiAnimation.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ @implementation TiAnimation
@synthesize delegate;
@synthesize zIndex, left, right, top, bottom, width, height;
@synthesize duration, color, backgroundColor, opacity, opaque, view;
@synthesize visible, curve, repeat, autoreverse, delay, transform, transition;
@synthesize visible, curve, repeat, autoreverse, delay, transform, transition, dampingRatio, springVelocity;
@synthesize animatedView, callback, isReverse, reverseAnimation, resetState;

- (id)initWithDictionary:(NSDictionary *)properties context:(id<TiEvaluator>)context_ callback:(KrollCallback *)callback_
Expand Down Expand Up @@ -95,6 +95,8 @@ - (id)initWithDictionary:(NSDictionary *)properties context:(id<TiEvaluator>)con
SET_FLOAT_PROP(duration, properties);
SET_FLOAT_PROP(opacity, properties);
SET_FLOAT_PROP(delay, properties);
SET_FLOAT_PROP(dampingRatio, properties);
SET_FLOAT_PROP(springVelocity, properties);
SET_INT_PROP(curve, properties);
SET_INT_PROP(repeat, properties);
SET_BOOL_PROP(visible, properties);
Expand Down Expand Up @@ -153,6 +155,8 @@ - (void)dealloc
RELEASE_TO_NIL(transition);
RELEASE_TO_NIL(callback);
RELEASE_TO_NIL(view);
RELEASE_TO_NIL(dampingRatio);
RELEASE_TO_NIL(springVelocity);
[animatedViewProxy release];
[super dealloc];
}
Expand Down Expand Up @@ -414,6 +418,10 @@ - (void)animate:(id)args
[reverseAnimation setIsReverse:YES];
[reverseAnimation setDuration:duration];
[reverseAnimation setDelay:[NSNumber numberWithInt:0]];
if (dampingRatio != nil || springVelocity != nil) {
[reverseAnimation setDampingRatio:dampingRatio];
[reverseAnimation setSpringVelocity:springVelocity];
}
switch ([curve intValue]) {
case UIViewAnimationOptionCurveEaseIn:
[reverseAnimation setCurve:[NSNumber numberWithInt:UIViewAnimationOptionCurveEaseOut]];
Expand Down Expand Up @@ -616,12 +624,22 @@ - (void)animate:(id)args
[self animationCompleted:[self description] finished:[NSNumber numberWithBool:finished] context:self];
}
};
if (dampingRatio != nil || springVelocity != nil) {
[UIView animateWithDuration:animationDuration
delay:([delay doubleValue] / 1000)
usingSpringWithDamping:[dampingRatio floatValue]
initialSpringVelocity:[springVelocity floatValue]
options:options
animations:animation
completion:complete];
} else {
[UIView animateWithDuration:animationDuration
delay:([delay doubleValue] / 1000)
options:options
animations:animation
completion:complete];
}

[UIView animateWithDuration:animationDuration
delay:([delay doubleValue] / 1000)
options:options
animations:animation
completion:complete];
} else {
BOOL perform = YES;

Expand Down