ts-transition-animation-shared-elements.md 2.9 KB
Newer Older
Z
zengyawen 已提交
1 2
# Transition of Shared Elements

E
ester.zhou 已提交
3
Shared element transition can be used for transition between pages, for example, transition from an image on the current page to the next page.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5
> **NOTE**
E
ester.zhou 已提交
6
>
E
ester.zhou 已提交
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.
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9

E
ester.zhou 已提交
10
## Attributes
Z
zengyawen 已提交
11 12


E
ester.zhou 已提交
13 14 15
| Name            | Parameters                                                        | Description                                                    |
| ---------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| 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, in ms. The default duration is 1000 ms.<br>- **curve**: animation curve. The default curve is **Linear**. For details about the valid values, see [Curve](ts-animatorproperty.md).<br>- **delay**: Delay of animation playback, in ms. By default, the playback is not delayed.<br>- **motionPath**: motion path information.<br>- **path**: path.<br>- **from**: start value.<br>- **to**: end value.<br>- **rotatable**: whether to rotate.<br>- **zIndex**: z-axis.<br>- **type**: animation type.|
Z
zengyawen 已提交
16 17 18


## Example
Z
zengyawen 已提交
19

E
ester.zhou 已提交
20
  The 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.
E
ester.zhou 已提交
21 22 23

```ts
// xxx.ets
Z
zengyawen 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
@Entry
@Component
struct SharedTransitionExample {
  @State active: boolean = false

  build() {
    List() {
      ListItem() {
        Row() {
          Navigator({ target: 'pages/common/Animation/transAnimation/PageB', type: NavigationType.Push }) {
            Image($r('app.media.ic_health_heart')).width(50).height(50)
              .sharedTransition('sharedImage1', { duration: 800, curve: Curve.Linear, delay: 100 })
          }.padding({ left: 10 })
          .onClick(() => {
            this.active = true
          })

          Text('SharedTransition').width(80).height(80).textAlign(TextAlign.Center)
        }
      }
    }
  }
}
```

E
ester.zhou 已提交
49 50
```ts
// PageB.ets
Z
zengyawen 已提交
51 52 53
@Entry
@Component
struct BExample {
E
ester.zhou 已提交
54

Z
zengyawen 已提交
55 56 57 58 59 60 61 62
  build() {
    Stack() {
      Image($r('app.media.ic_health_heart')).width(150).height(150).sharedTransition('sharedImage1')
    }.width('100%').height(400)
  }
}
```

Z
zengyawen 已提交
63
![en-us_image_0000001211898494](figures/en-us_image_0000001211898494.gif)