• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * Defines the animator options.
18 * @interface
19 * @syscap SystemCapability.ArkUI.ArkUI.Full
20 * @since 6
21 */
22export interface AnimatorOptions {
23  /**
24   * Duration of the animation, in milliseconds.
25   * The default value is 0.
26   * @type {number}
27   * @since 6
28   */
29  duration: number;
30
31  /**
32   * Time curve of the animation. For details about the supported types.
33   * linear The animation speed keeps unchanged.
34   * ease The animation starts and ends at a low speed, cubic-bezier(0.25, 0.1, 0.25, 1.0).
35   * ease-in The animation starts at a low speed, cubic-bezier(0.42, 0.0, 1.0, 1.0).
36   * ease-out The animation ends at a low speed, cubic-bezier(0.0, 0.0, 0.58, 1.0).
37   * ease-in-out The animation starts and ends at a low speed, cubic-bezier(0.42, 0.0, 0.58, 1.0).
38   * fast-out-slow-in Standard curve, cubic-bezier(0.4, 0.0, 0.2, 1.0).
39   * linear-out-slow-in Deceleration curve, cubic-bezier(0.0, 0.0, 0.2, 1.0).
40   * fast-out-linear-in Acceleration curve, cubic-bezier(0.4, 0.0, 1.0, 1.0).
41   * friction Damping curve, cubic-bezier(0.2, 0.0, 0.2, 1.0).
42   * extreme-deceleration Extreme deceleration curve, cubic-bezier(0.0, 0.0, 0.0, 1.0).
43   * sharp Sharp curve, cubic-bezier(0.33, 0.0, 0.67, 1.0).
44   * rhythm Rhythm curve, cubic-bezier(0.7, 0.0, 0.2, 1.0).
45   * smooth Smooth curve, cubic-bezier(0.4, 0.0, 0.4, 1.0).
46   * cubic-bezier(x1, y1, x2, y2) You can customize an animation speed curve in the cubic-bezier() function. The x and y values of each input parameter must be between 0 and 1.
47   * Step curve. The number must be set and only an integer is supported, step-position is optional. It can be set to start or end. The default value is end.
48   * The default value is ease.
49   * @type {string}
50   * @since 6
51   */
52  easing: string;
53
54  /**
55   * Delay for the animation start. The default value indicates no delay.
56   * The default value is 0.
57   * @type {number}
58   * @since 6
59   */
60  delay: number;
61
62  /**
63   * Whether to resume to the initial state after the animation is executed.
64   * none: The initial state is restored after the animation is executed.
65   * forwards: The state at the end of the animation (defined in the last key frame) is retained after the animation is executed.
66   * @type {string}
67   * @since 6
68   */
69  fill: "none" | "forwards" | "backwards" | "both";
70
71  /**
72   * The animation playback mode.
73   * The default value is "normal".
74   * @type {string}
75   * @since 6
76   */
77  direction: "normal" | "reverse" | "alternate" | "alternate-reverse";
78
79  /**
80   * Number of times the animation will be played. number indicates a fixed number of playback operations, and -1 an unlimited number of playback operations.
81   * The default value is 1.
82   * @type {number}
83   * @since 6
84   */
85  iterations: number;
86
87  /**
88   * Starting point of animator interpolation.
89   * The default value is 0.
90   * @type {number}
91   * @since 6
92   */
93  begin: number;
94
95  /**
96   * Ending point of Dynamic Interpolation
97   * The default value is 1.
98   * @type {number}
99   * @since 6
100   */
101  end: number;
102}
103
104/**
105 * Defines the Animator result interface.
106 * @interface
107 * @syscap SystemCapability.ArkUI.ArkUI.Full
108 * @since 6
109 */
110export interface AnimatorResult {
111  /**
112   * Update the options for current animator.
113   * @param { AnimatorOptions } options - Options.
114   * @syscap SystemCapability.ArkUI.ArkUI.Full
115   * @since 6
116   * @deprecated since 9
117   * @useinstead ohos.animator.reset
118   */
119  update(options: AnimatorOptions): void;
120  /**
121   * Reset the options for current animator.
122   * @param { AnimatorOptions } options - Options.
123   * @throws { BusinessError } 401 - if the type of the parameter 1 is not object.
124   * @throws { BusinessError } 100001 - if no page is found for pageId or fail to get object property list.
125   * @syscap SystemCapability.ArkUI.ArkUI.Full
126   * @since 9
127   */
128  reset(options: AnimatorOptions): void;
129  /**
130   * Starts the animation.
131   * @syscap SystemCapability.ArkUI.ArkUI.Full
132   * @since 6
133   */
134  play(): void;
135  /**
136   * Ends the animation.
137   * @syscap SystemCapability.ArkUI.ArkUI.Full
138   * @since 6
139   */
140  finish(): void;
141  /**
142   * Pauses the animation.
143   * @syscap SystemCapability.ArkUI.ArkUI.Full
144   * @since 6
145   */
146  pause(): void;
147  /**
148   * Cancels the animation.
149   * @syscap SystemCapability.ArkUI.ArkUI.Full
150   * @since 6
151   */
152  cancel(): void;
153  /**
154   * Plays the animation in reverse direction.
155   * @syscap SystemCapability.ArkUI.ArkUI.Full
156   * @since 6
157   */
158  reverse(): void;
159  /**
160   * Trigger when vsync callback.
161   * @param { number } progress - The current progress of animation
162   * @syscap SystemCapability.ArkUI.ArkUI.Full
163   * @since 6
164   */
165  onframe: (progress: number) => void;
166  /**
167   * The animation is finished.
168   * @syscap SystemCapability.ArkUI.ArkUI.Full
169   * @since 6
170   */
171  onfinish: () => void;
172  /**
173   * The animation is canceled.
174   * @syscap SystemCapability.ArkUI.ArkUI.Full
175   * @since 6
176   */
177  oncancel: () => void;
178  /**
179   * The animation is repeated.
180   * @syscap SystemCapability.ArkUI.ArkUI.Full
181   * @since 6
182   */
183  onrepeat: () => void;
184}
185
186/**
187 * Defines the Animator class.
188 * @syscap SystemCapability.ArkUI.ArkUI.Full
189 * @since 6
190 */
191export default class Animator {
192  /**
193   * Create an animator object for custom animation.
194   * @param { AnimatorOptions } options - Options.
195   * @syscap SystemCapability.ArkUI.ArkUI.Full
196   * @since 6
197   * @deprecated since 9
198   * @useinstead ohos.animator.create
199   */
200  static createAnimator(options: AnimatorOptions): AnimatorResult;
201  /**
202   * Create an animator object for custom animation.
203   * @param { AnimatorOptions } options - Options.
204   * @throws { BusinessError } 401 - if parameter error.
205   * @syscap SystemCapability.ArkUI.ArkUI.Full
206   * @since 9
207   */
208   static create(options: AnimatorOptions): AnimatorResult;
209}
210