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 * @syscap SystemCapability.ArkUI.ArkUI.Full 19 * @since 6 20 */ 21export interface AnimatorOptions { 22 /** 23 * Duration of the animation, in milliseconds. 24 * The default value is 0. 25 * @since 6 26 */ 27 duration: number; 28 29 /** 30 * Time curve of the animation. For details about the supported types. 31 * linear The animation speed keeps unchanged. 32 * ease The animation starts and ends at a low speed, cubic-bezier(0.25, 0.1, 0.25, 1.0). 33 * ease-in The animation starts at a low speed, cubic-bezier(0.42, 0.0, 1.0, 1.0). 34 * ease-out The animation ends at a low speed, cubic-bezier(0.0, 0.0, 0.58, 1.0). 35 * ease-in-out The animation starts and ends at a low speed, cubic-bezier(0.42, 0.0, 0.58, 1.0). 36 * fast-out-slow-in Standard curve, cubic-bezier(0.4, 0.0, 0.2, 1.0). 37 * linear-out-slow-in Deceleration curve, cubic-bezier(0.0, 0.0, 0.2, 1.0). 38 * fast-out-linear-in Acceleration curve, cubic-bezier(0.4, 0.0, 1.0, 1.0). 39 * friction Damping curve, cubic-bezier(0.2, 0.0, 0.2, 1.0). 40 * extreme-deceleration Extreme deceleration curve, cubic-bezier(0.0, 0.0, 0.0, 1.0). 41 * sharp Sharp curve, cubic-bezier(0.33, 0.0, 0.67, 1.0). 42 * rhythm Rhythm curve, cubic-bezier(0.7, 0.0, 0.2, 1.0). 43 * smooth Smooth curve, cubic-bezier(0.4, 0.0, 0.4, 1.0). 44 * 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. 45 * 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. 46 * The default value is ease. 47 * @since 6 48 */ 49 easing: string; 50 51 /** 52 * Delay for the animation start. The default value indicates no delay. 53 * The default value is 0. 54 * @since 6 55 */ 56 delay: number; 57 58 /** 59 * Whether to resume to the initial state after the animation is executed. 60 * none: The initial state is restored after the animation is executed. 61 * forwards: The state at the end of the animation (defined in the last key frame) is retained after the animation is executed. 62 * @since 6 63 */ 64 fill: "none" | "forwards" | "backwards" | "both"; 65 66 /** 67 * The animation playback mode. 68 * The default value is "normal". 69 * @since 6 70 */ 71 direction: "normal" | "reverse" | "alternate" | "alternate-reverse"; 72 73 /** 74 * Number of times the animation will be played. number indicates a fixed number of playback operations, and -1 an unlimited number of playback operations. 75 * The default value is 1. 76 * @since 6 77 */ 78 iterations: number; 79 80 /** 81 * Starting point of animator interpolation. 82 * The default value is 0. 83 * @since 6 84 */ 85 begin: number; 86 87 /** 88 * Ending point of Dynamic Interpolation 89 * The default value is 1. 90 * @since 6 91 */ 92 end: number; 93} 94 95/** 96 * Defines the Animator result interface. 97 * @syscap SystemCapability.ArkUI.ArkUI.Full 98 * @since 6 99 */ 100export interface AnimatorResult { 101 /** 102 * Update the options for current animator. 103 * @param options Options. 104 * @since 6 105 */ 106 update(options: AnimatorOptions): void; 107 /** 108 * Starts the animation. 109 * @since 6 110 */ 111 play(): void; 112 /** 113 * Ends the animation. 114 * @since 6 115 */ 116 finish(): void; 117 /** 118 * Pauses the animation. 119 * @since 6 120 */ 121 pause(): void; 122 /** 123 * Cancels the animation. 124 * @since 6 125 */ 126 cancel(): void; 127 /** 128 * Plays the animation in reverse direction. 129 * @since 6 130 */ 131 reverse(): void; 132 /** 133 * Trigger when vsync callback. 134 * @param progress The current progress of animtion 135 * @since 6 136 */ 137 onframe: (progress: number) => void; 138 /** 139 * The animation is finished. 140 * @since 6 141 */ 142 onfinish: () => void; 143 /** 144 * The animation is canceled. 145 * @since 6 146 */ 147 oncancel: () => void; 148 /** 149 * The animation is repeated. 150 * @since 6 151 */ 152 onrepeat: () => void; 153} 154 155/** 156 * Defines the Animator class. 157 * @syscap SystemCapability.ArkUI.ArkUI.Full 158 * @since 6 159 * @import prompt from '@ohos.animator'; 160 */ 161export default class Animator { 162 /** 163 * Create an animator object for custum animation. 164 * @param options Options. 165 * @since 6 166 */ 167 static createAnimator(options: AnimatorOptions): AnimatorResult; 168} 169