• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Shared Element Transition
2
3A shared element transition is a transition animation applied to a component that is present on two pages. This component is called the shared element and can be set in the **sharedTransition** attribute.
4
5> **NOTE**
6>
7> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## Attributes
11
12
13| Name            | Parameter                                                        | Description                                                    |
14| ---------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
15| sharedTransition | id: string,<br>{<br> duration?: number,<br> curve?: Curve \| string,<br> delay?: number,<br> motionPath?: <br>{<br> path: string,<br> form?: number,<br> to?: number,<br> rotatable?: boolean<br>},<br>zIndex?: number,<br>type?: [SharedTransitionEffectType](ts-appendix-enums.md#sharedtransitioneffecttype)<br>} | Transition of the shared element. If the same **id** value is configured for a component on the two pages, this component is considered as a shared element of the pages. If the **id** value is an empty string, no transition will be applied to the component.<br>- **id**: component ID.<br>- **duration**: animation duration.<br>Default value: **1000**<br>Unit: ms<br>Value range: [0, +∞)<br>The value **0** indicates that no animation is applied. A value less than 0 evaluates to the value **0**.<br>- **curve**: animation curve. The default curve is **Linear**. For details about the valid values, see [Curve](ts-animatorproperty.md).<br>- **delay**: animation delay.<br>Default value: **0**<br>Unit: ms<br>Value range: [0, +∞)<br>A value less than 0 evaluates to the value **0**.<br>- **motionPath**: motion path information. For details, see [Motion Path Animation](ts-motion-path-animation.md).<br>- **path**: path.<br>- **from**: start value.<br>- **to**: end value.<br>- **rotatable**: whether to rotate.<br>- **zIndex**: z-axis.<br>- **type**: animation type.|
16
17
18## Example
19
20This example implements the custom transition of a shared image during redirection from one page to another, which is triggered by a click on the image.
21
22```ts
23// xxx.ets
24@Entry
25@Component
26struct SharedTransitionExample {
27  @State active: boolean = false
28
29  build() {
30    Column() {
31      Navigator({ target: 'pages/PageB', type: NavigationType.Push }) {
32        Image($r('app.media.ic_health_heart')).width(50).height(50)
33          .sharedTransition('sharedImage', { duration: 800, curve: Curve.Linear, delay: 100 })
34      }.padding({ left: 20, top: 20 })
35      .onClick(() => {
36        this.active = true
37      })
38    }
39  }
40}
41```
42
43```ts
44// PageB.ets
45@Entry
46@Component
47struct pageBExample {
48  build() {
49    Stack() {
50      Image($r('app.media.ic_health_heart')).width(150).height(150)
51        .sharedTransition('sharedImage', { duration: 800, curve: Curve.Linear, delay: 100 })
52    }.width('100%').height('100%')
53  }
54}
55```
56
57![shared](figures/shared.gif)
58