Skip to content

Commit 6871521

Browse files
committed
Merge pull request NativeScript#235 from NativeScript/raikov/animation-custom-timing
Add section about animation curves in animations article
2 parents 6ccd7e8 + 3ec896d commit 6871521

File tree

8 files changed

+66
-0
lines changed

8 files changed

+66
-0
lines changed
5.62 KB
Loading

img/modules/animation/bezier.gif

77.7 KB
Loading

img/modules/animation/easein.gif

87.6 KB
Loading

img/modules/animation/easeinout.gif

85.2 KB
Loading

img/modules/animation/easeout.gif

88 KB
Loading

img/modules/animation/linear.gif

89.9 KB
Loading

img/modules/animation/spring.gif

86.3 KB
Loading

ui/animation.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,71 @@ The [`Animation`]({{site.baseurl}}/ApiReference/ui/animation/Animation.md) class
4242
## View.animate Method
4343
In case you need to animate a **single** [`View`]({{site.baseurl}}/ApiReference/ui/core/view/View.md) and you don't need to be able to **cancel** the animation, you can simply use the shortcut **View.animate** method which accepts an [`AnimationDefinition`]({{site.baseurl}}/ApiReference/ui/animation/AnimationDefinition.md), immediately starts the animation and returns its finished promise.
4444

45+
## Animation curves
46+
47+
By default the animation moves with a linear speed without acceleration or deceleration. This might look unnatural and different from the real world where objects need time to reach their top speed and can't stop immediately. The animation curve (called sometimes easing function) is used to give animations an illusion of inertia. It controls the animation speed by modifying the fraction of the duration. NativeScript comes with a number of predefined animation curves:
48+
49+
- The simplest animation curve is linear. It maintains a constant speed while the animation is running:
50+
51+
![linear]({{site.baseurl}}/img/modules/animation/linear.gif "Linear")
52+
53+
- The ease-in curve causes the animation to begin slowly, and then speed up as it progresses.
54+
55+
![easein]({{site.baseurl}}/img/modules/animation/easein.gif "EaseIn")
56+
57+
- An ease-out curve causes the animation to begin quickly, and then slow down as it completes.
58+
59+
![easeout]({{site.baseurl}}/img/modules/animation/easeout.gif "EaseOut")
60+
61+
62+
- An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing.
63+
64+
![easeinout]({{site.baseurl}}/img/modules/animation/easeinout.gif "EaseInOut")
65+
66+
67+
- A spring animation curve causes an animation to produce a spring (bounce) effect.
68+
69+
![spring]({{site.baseurl}}/img/modules/animation/spring.gif "Spring")
70+
71+
72+
In NativeScript the animation curve is represented by the AnimationCurve enumeration and can be specified with the curve property of the animation:
73+
74+
``` JavaScript
75+
view.animate({
76+
translate: { x: 0, y: 100},
77+
duration: 1000,
78+
curve: enums.AnimationCurve.easeIn
79+
});
80+
```
81+
``` TypeScript
82+
view.animate({
83+
translate: { x: 0, y: 100},
84+
duration: 1000,
85+
curve: enums.AnimationCurve.easeIn
86+
});
87+
```
88+
89+
It is easy to create your own animation curve by passing in the x and y components of two control points of a cubic Bezier curve. Using Bezier curves is a common technique to create smooth curves in computer graphics and they are widely used in vector-based drawing tools. The values passed to the cubicBezier method control the curve shape. The animation speed will be adjusted based on the resulting path.
90+
91+
![beziergraph]({{site.baseurl}}/img/modules/animation/bezier-graph.png "BezierGraph")
92+
93+
``` JavaScript
94+
view.animate({
95+
translate: { x: 0, y: 100 },
96+
duration: 1000,
97+
curve: enums.AnimationCurve.cubicBezier(0.1, 0.1, 0.1, 1)
98+
});
99+
```
100+
``` TypeScript
101+
view.animate({
102+
translate: { x: 0, y: 100 },
103+
duration: 1000,
104+
curve: enums.AnimationCurve.cubicBezier(0.1, 0.1, 0.1, 1)
105+
});
106+
```
107+
108+
![bezier]({{site.baseurl}}/img/modules/animation/bezier.gif "Bezier")
109+
45110
# Examples
46111

47112
The full source code for all samples is located [`here`](https://github.com/NativeScript/animation-demo).
@@ -379,3 +444,4 @@ animationSet.play().catch((e) => {
379444
});
380445
// Call animationSet.cancel() to stop it;
381446
```
447+

0 commit comments

Comments
 (0)