The ArkUI development framework provides animation APIs in the NDK APIs, enabling you to implement efficient and refined animation effects using C and C++ code in your app. These include property animation, component appearing/disappearing transition, shared element transition, and keyframe animation. It also supports bridging the frame animation capability from the ArkTS side through Node-API, covering most animation scenarios in native UI development. The core animation capabilities include:
Property animation
Property animation refers to UI changes caused by changes in certain attributes (such as size attributes, layout attributes, and position attributes). Adding a property animation allows attribute values to gradually change from the start point to the end point, producing a continuous animation effect. You can implement property animation using the global animateTo explicit animation API. By setting state changes in a closure function, the system automatically inserts transition animations. For animations that change layout attributes (such as width and height), the content usually jumps directly to the final state, for example, text. If you want the content to follow the width and height changes, you can use the NODE_RENDER_FIT attribute in ArkUI_NodeAttributeType for configuration. For specific usage scenarios, refer to the example Using Property Animation.
Component appearing/disappearing transition
Component appearing/disappearing transition is mainly used to automatically trigger entrance/exit transition effects when inserting and deleting child components in a container component, improving the user experience. It supports configuring transition parameters through the NODE_ROTATE_TRANSITION, NODE_SCALE_TRANSITION, NODE_TRANSLATE_TRANSITION, NODE_OPACITY_TRANSITION, and NODE_MOVE_TRANSITION attributes in ArkUI_NodeAttributeType, corresponding to five transition types: rotation, scaling, translation, opacity, and movement. You can independently configure the animation duration, animation curve, and other parameters for the transition, without manually controlling the animation start and stop. The corresponding effects are automatically triggered when components are attached to or detached from the component tree. For specific usage scenarios, refer to the example Component Appearance/Disappearance Transition.
One-shot transition
One-shot transition is mainly used to create a transition animation effect that matches the position and size of two identical or similar elements during screen switching, also known as a shared element transition. The one-shot transition effect creates a linkage between the appearance and disappearance of two elements, making the content switching process smooth and natural rather than abrupt.
The NODE_GEOMETRY_TRANSITION attribute in ArkUI_NodeAttributeType is used for implicit shared element transitions within components, providing a seamless context inheritance transition experience during view state switching. By binding the same id to two components through the NODE_GEOMETRY_TRANSITION attribute in ArkUI_NodeAttributeType, the system adds a one-shot transition effect when one component is removed and another is added. The implementation approach of binding two objects distinguishes the NODE_GEOMETRY_TRANSITION attribute in ArkUI_NodeAttributeType from other methods, making it most suitable for completing a one-shot transition between two different objects. For specific usage scenarios, refer to the example Shared Element Transition.
Keyframe animation
Keyframe animation uses the keyframeAnimateTo API to specify multiple keyframe states, achieving segmented, multi-stage complex animation effects. It supports independently setting the animation duration for different keyframe nodes, enabling non-linear and multi-rhythm animation changes. You can customize the number of loop iterations and the expected frame rate range for the overall animation. It also supports a state change closure for each keyframe and a global animation end callback, making it suitable for more complex animation development scenarios. For specific usage scenarios, refer to the example Using Keyframe Animation.
Frame animation
Frame animation features per-frame callbacks, making it convenient for you to adjust the required attributes in each frame. By providing the OH_ArkUI_AnimatorOption_RegisterOnFrameCallback per-frame callback function, frame animation allows you to set attribute values in each frame of the app, thereby achieving a natural transition of component attribute value changes and creating a smooth animation effect. For the frame animation API, refer to createAnimator.
Compared with property animation, frame animation allows you to perceive the animation progress in real time, adjust UI values instantly, and offers the advantages of immediate event response and pausability, but it is slightly inferior in performance. When property animation can meet your requirements, it is recommended to use the property animation API first. For the usage of the animateTo API, refer to Using Property Animation. For specific usage scenarios of frame animation, refer to the example Using Frame Animation.