A 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, , which is effective only during page routing transitions.
This feature is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
This 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.
// xxx.ets
@Entry
@Component
struct SharedTransitionExample {
build() {
Column() {
// Replace $r('app.media.ic_health_heart') with the image resource file you use.
Image($r('app.media.ic_health_heart')).width(50).height(50).margin({ left: 20, top: 20 })
.sharedTransition('sharedImage', { duration: 800, curve: Curve.Linear, delay: 100 })
}.width('100%').height('100%').alignItems(HorizontalAlign.Start)
.onClick(() => {
this.getUIContext().getRouter().pushUrl({ url: 'pages/PageB' })
})
}
pageTransition() {
PageTransitionEnter({ type: RouteType.None, duration: 0 })
PageTransitionExit({ type: RouteType.None, duration: 0 })
}
} // PageB.ets
@Entry
@Component
struct PageBExample {
build() {
Stack() {
// Replace $r('app.media.ic_health_heart') with the image resource file you use.
Image($r('app.media.ic_health_heart')).width(150).height(150)
.sharedTransition('sharedImage', { duration: 800, curve: Curve.Linear, delay: 100 })
}.width('100%').height('100%')
}
pageTransition() {
PageTransitionEnter({ type: RouteType.None, duration: 0 })
PageTransitionExit({ type: RouteType.None, duration: 0 })
}
} 