• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Page Transition (pageTransition)
2
3You can customize the page entrance and exit animations in the **pageTransition** API for transition between pages. For details, see [Page Transition Animation](../../../ui/arkts-page-transition-animation.md).
4
5> **NOTE**
6>
7> This event is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8>
9> To achieve a better transition effect, you are advised to use the [Navigation](../../../ui/arkts-navigation-navigation.md) component and [modal transition](../../../ui/arkts-modal-transition.md).
10
11## pageTransition
12
13pageTransition?(): void
14
15Defines the transition animation to play when the user accesses this page or is redirected from this page to another page.
16
17**Atomic service API**: This API can be used in atomic services since API version 11.
18
19**System capability**: SystemCapability.ArkUI.ArkUI.Full
20
21## PageTransitionEnter
22
23PageTransitionEnter(value: PageTransitionOptions)
24
25Sets the page entrance animation. Inherits from [CommonTransition](#commontransition).
26
27**Atomic service API**: This API can be used in atomic services since API version 11.
28
29**System capability**: SystemCapability.ArkUI.ArkUI.Full
30
31**Parameters**
32
33| Name| Type                                                  | Mandatory| Description                |
34| ------ | ------------------------------------------------------ | ---- | -------------------- |
35| value  | [PageTransitionOptions](#pagetransitionoptions) | Yes  | Page entrance animation.|
36
37### onEnter
38
39onEnter(event: PageTransitionCallback): PageTransitionEnterInterface
40
41Invoked on a per-frame basis until the entrance animation is complete, with the **progress** parameter changing from 0 to 1.
42
43**Atomic service API**: This API can be used in atomic services since API version 11.
44
45**System capability**: SystemCapability.ArkUI.ArkUI.Full
46
47**Parameters**
48
49| Name| Type                                                              | Mandatory| Description                                               |
50| ------ | ----------------------------------------------------------------- | ---- | ------------------------------------------------    |
51| event  | [PageTransitionCallback](#pagetransitioncallback14) | Yes  | Callback invoked on a per-frame basis until the entrance animation is complete, with the **progress** parameter changing from 0 to 1.|
52
53**Example**
54
55```js
56  pageTransition() {
57    PageTransitionEnter({ duration: 1200, curve: Curve.Linear })
58      // During the transition animation, the entrance animation has a type that represents the route type, and a progress that increases from 0 to 1.
59      .onEnter((type: RouteType, progress: number) => {
60        // Service logic
61      })
62  }
63```
64
65## PageTransitionExit
66
67PageTransitionExit(value: PageTransitionOptions)
68
69Sets the page exit animation. Inherits from [CommonTransition](#commontransition).
70
71**Atomic service API**: This API can be used in atomic services since API version 11.
72
73**System capability**: SystemCapability.ArkUI.ArkUI.Full
74
75**Parameters**
76
77| Name| Type                                                   | Mandatory| Description                |
78| ------ | ------------------------------------------------------- | ---- | -------------------- |
79| value  | [PageTransitionOptions](#pagetransitionoptions) | Yes  | Page exit animation.|
80
81### onExit
82
83onExit(event: PageTransitionCallback): PageTransitionExitInterface
84
85Invoked on a per-frame basis until the exit animation is complete, with the **progress** parameter changing from 0 to 1.
86
87**System capability**: SystemCapability.ArkUI.ArkUI.Full
88
89**Atomic service API**: This API can be used in atomic services since API version 11.
90
91**Parameters**
92
93| Name| Type                                                              | Mandatory| Description                                               |
94| ------ | ----------------------------------------------------------------- | ---- | ------------------------------------------------    |
95| event  | [PageTransitionCallback](#pagetransitioncallback14) | Yes  | Callback invoked on a per-frame basis until the exit animation is complete, with the **progress** parameter changing from 0 to 1.|
96
97**Example**
98
99```js
100  pageTransition() {
101    PageTransitionExit({ duration: 1200, curve: Curve.Linear })
102      // During the transition animation, the exit animation has a type that represents the route type, and a progress that increases from 0 to 1.
103      .onExit((type: RouteType, progress: number) => {
104        // Service logic
105      })
106  }
107```
108
109## PageTransitionOptions
110
111**Atomic service API**: This API can be used in atomic services since API version 11.
112
113**System capability**: SystemCapability.ArkUI.ArkUI.Full
114
115| Name    | Type                                                        | Mandatory| Description                                                        |
116| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
117| type     | [RouteType](#routetype)                              | No  | Route type for the page transition effect to take effect.<br>Default value: **RouteType.None**   |
118| duration | number                                                       | No  | Animation duration.<br>Unit: ms<br>Default value: **1000**<br>Value range: [0, +∞)                |
119| curve    | [Curve](ts-appendix-enums.md#curve) \| string \| [ICurve](../js-apis-curve.md#icurve9)<sup>10+</sup> | No  | Animation curve.<br>You are advised to specify the curve using the **Curve** or** ICurve** type.<br>For the string type, this parameter indicates an animation interpolation curve. For available values, see the **curve** parameter in [AnimateParam](./ts-explicit-animation.md#animateparam).<br>Default value: **Curve.Linear**|
120| delay    | number                                                       | No  | Animation delay.<br>Unit: ms<br>Default value: **0**<br>**NOTE**<br>If no match is found, the default page transition effect is used (which may vary according to the device). To disable the default page transition effect, set **duration** to **0**.|
121
122## CommonTransition
123
124Defines a common transition animation for page transitions.
125
126**Atomic service API**: This API can be used in atomic services since API version 11.
127
128**System capability**: SystemCapability.ArkUI.ArkUI.Full
129
130### constructor
131
132constructor()
133
134A constructor used to create a common transition animation.
135
136**Atomic service API**: This API can be used in atomic services since API version 11.
137
138**System capability**: SystemCapability.ArkUI.ArkUI.Full
139
140### slide
141
142slide(value: SlideEffect): T
143
144Sets the slide-in and slide-out effects for page transitions.
145
146**Atomic service API**: This API can be used in atomic services since API version 11.
147
148**System capability**: SystemCapability.ArkUI.ArkUI.Full
149
150**Parameters**
151
152| Name | Type                                                        | Mandatory| Description                                                        |
153| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
154| value   | [SlideEffect](#slideeffect) | Yes  | Slide-in and slide-out effects for page transitions.|
155
156### translate
157
158translate(value: TranslateOptions): T
159
160Sets the translation effect for page transitions.
161
162**Atomic service API**: This API can be used in atomic services since API version 11.
163
164**System capability**: SystemCapability.ArkUI.ArkUI.Full
165
166**Parameters**
167
168| Name| Type                                                        | Mandatory| Description                                                        |
169| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
170| value  | [TranslateOptions](ts-universal-attributes-transformation.md#translateoptions) | Yes  | Translation effect for page transitions, specifying the start value for entrance and the end value for exit. When this parameter is set together with **slide**, the latter takes effect by default.<br>- **x**: translation distance along the x-axis.<br>- **y**: translation distance along the y-axis.<br>- **z**: translation distance along the y-axis.|
171
172### scale
173
174scale(value: ScaleOptions): T
175
176Sets the scaling effect for page transitions.
177
178**Atomic service API**: This API can be used in atomic services since API version 11.
179
180**System capability**: SystemCapability.ArkUI.ArkUI.Full
181
182**Parameters**
183
184| Name| Type                                                        | Mandatory| Description                                                        |
185| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
186| value  | [ScaleOptions](ts-universal-attributes-transformation.md#scaleoptions) | Yes  | Scaling effect for page transitions, specifying the start value for entrance and the end value for exit.<br>- **x**: scale factor along the x-axis.<br>- **y**: scale factor along the y-axis.<br>- **z**: scale factor along the z-axis.<br>- **centerX** and **centerY**: scaling center. The default values are both **"50%"**, meaning the center of the page is used as the scaling center by default.<br>- If the center point is (0, 0), it refers to the upper left corner of the component.|
187
188### opacity
189
190opacity(value: number): T
191
192Sets the starting opacity value for entrance or the ending opacity value for exit.
193
194**Atomic service API**: This API can be used in atomic services since API version 11.
195
196**System capability**: SystemCapability.ArkUI.ArkUI.Full
197
198**Parameters**
199
200| Name | Type                                                        | Mandatory| Description                                                        |
201| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
202| value   | number | Yes  | Starting opacity value for entrance or the ending opacity value for exit.<br>Value range: [0, 1]|
203
204## PageTransitionCallback<sup>14+</sup>
205
206type PageTransitionCallback = (type: RouteType, progress: number) => void
207
208Represents the callback for page transition events.
209
210**Atomic service API**: This API can be used in atomic services since API version 14.
211
212**System capability**: SystemCapability.ArkUI.ArkUI.Full
213
214| Name | Type   | Mandatory| Description             |
215| ------ | ------ | ---- | ---------------- |
216| type | [RouteType](#routetype) | Yes|  Type of page transition.|
217| progress | number | Yes| Transition progress, ranging from 0 to 1.|
218
219 ## RouteType
220
221**System capability**: SystemCapability.ArkUI.ArkUI.Full
222
223**Atomic service API**: This API can be used in atomic services since API version 11.
224
225
226| Name| Description                                                        |
227| ---- | ------------------------------------------------------------ |
228| Pop  | Redirects to a specified page. To redirect the user from page B back to page A, set **RouteType** of **PageTransitionExit** to **None** or **Pop** for page B and set **RouteType** of **PageTransitionEnter** to **None** or **Pop** for page A.|
229| Push | Redirects to the next page. To redirect the user from page A to page B, set **RouteType** of **PageTransitionExit** to **None** or **Push** for page A and set **RouteType** of **PageTransitionEnter** to **None** or **Push** for page B.|
230| None | The page is not redirected. The animation specified by **PageTransitionEnter** takes effect for page entrance, and the animation specified by **PageTransitionExit** takes effect for page exit.|
231
232## SlideEffect
233
234**Atomic service API**: This API can be used in atomic services since API version 11.
235
236**System capability**: SystemCapability.ArkUI.ArkUI.Full
237
238| Name               | Description                                                        |
239| ------------------- | ------------------------------------------------------------ |
240| Left                | When set to Enter, slides in from the left. When set to Exit, slides out to the left.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
241| Right               | When set to Enter, slides in from the right. When set to Exit, slides out to the right.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
242| Top                 | When set to Enter, slides in from the top. When set to Exit, slides out to the top.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
243| Bottom              | When set to Enter, slides in from the bottom. When set to Exit, slides out to the bottom.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
244| START<sup>12+</sup> | Left-to-right scripts: When set to Enter, slides in from the left; when set to Exit, slides out to the left. Right-to-left scripts: When set to Enter, slides in from the right; when set to Exit, slides out to the right.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
245| END<sup>12+</sup>   | Left-to-right scripts: When set to Enter, slides in from the right; when set to Exit, slides out to the right. Right-to-left scripts: When set to Enter, slides in from the left; when set to Exit, slides out to the left.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
246
247## Example
248
249### Example 1: Configuring Entrance and Exit Animations
250
251Method 1: Configure different entrance and exit animations based on different transition types.
252
253```ts
254// index.ets
255import { router } from '@kit.ArkUI';
256
257@Entry
258@Component
259struct Index {
260  @State scale1: number = 1
261  @State opacity1: number = 1
262
263  build() {
264    Column() {
265      Image($r("app.media.transition_image1")).width('100%').height('100%')
266    }
267    .width('100%')
268    .height('100%')
269    .scale({ x: this.scale1 })
270    .opacity(this.opacity1)
271    .onClick(() => {
272      router.pushUrl({ url: 'pages/Page1' })
273    })
274  }
275
276  pageTransition() {
277    PageTransitionEnter({ duration: 1200, curve: Curve.Linear })
278      .onEnter((type: RouteType, progress: number) => {
279        if (type == RouteType.Push || type == RouteType.Pop) {
280          this.scale1 = progress
281          this.opacity1 = progress
282        }
283      })
284    PageTransitionExit({ duration: 1200, curve: Curve.Ease })
285      .onExit((type: RouteType, progress: number) => {
286        if (type == RouteType.Push) {
287          this.scale1 = 1 - progress
288          this.opacity1 = 1 - progress
289        }
290      })
291  }
292}
293```
294
295```ts
296// page1.ets
297import { router } from '@kit.ArkUI';
298
299@Entry
300@Component
301struct Page1 {
302  @State scale2: number = 1
303  @State opacity2: number = 1
304
305  build() {
306    Column() {
307      Image($r("app.media.transition_image2")).width('100%').height('100%') // Store the image in the media folder.
308    }
309    .width('100%')
310    .height('100%')
311    .scale({ x: this.scale2 })
312    .opacity(this.opacity2)
313    .onClick(() => {
314      router.pushUrl({ url: 'pages/Index' })
315    })
316  }
317
318  pageTransition() {
319    PageTransitionEnter({ duration: 1200, curve: Curve.Linear })
320      .onEnter((type: RouteType, progress: number) => {
321        if (type == RouteType.Push || type == RouteType.Pop) {
322          this.scale2 = progress
323        }
324        this.opacity2 = progress
325      })
326    PageTransitionExit({ duration: 1200, curve: Curve.Ease })
327      .onExit((type: RouteType, progress: number) => {
328        if (type == RouteType.Pop) {
329          this.scale2 = 1 - progress
330          this.opacity2 = 1 - progress
331        }
332      })
333  }
334}
335```
336
337![pageTransition1](figures/pageTransition1.gif)
338
339Method 2: Configure the entrance animation of sliding in from the left and the exit animation of translating with opacity change.
340
341```ts
342// index.ets
343@Entry
344@Component
345struct PageTransitionExample {
346  build() {
347    Column() {
348      Navigator({ target: 'pages/page1', type: NavigationType.Push }) {
349        Image($r("app.media.transition_image2")).width('100%').height('100%') // The image is stored in the media folder.
350      }
351    }
352  }
353
354  // Use the default effects provided by the system, such as translation, scaling, and opacity.
355  pageTransition() {
356    // Set the duration of the entrance animation to 1200 ms, in the purpose of matching the duration of the exit animation of the other page.
357    PageTransitionEnter({ duration: 1200 })
358      .slide(SlideEffect.Left)
359    // Set the duration of the exit animation to 1000 ms, in the purpose of matching the duration of the entrance animation of the other page.
360    PageTransitionExit({ duration: 1000 })
361      .translate({ x: 100.0, y: 100.0 })
362      .opacity(0)
363  }
364}
365```
366
367```ts
368// page1.ets
369@Entry
370@Component
371struct PageTransitionExample1 {
372  build() {
373    Column() {
374      Navigator({ target: 'pages/index', type: NavigationType.Push }) {
375        Image($r('app.media.bg2')).width('100%').height('100%') // The image is stored in the media folder.
376      }
377    }
378  }
379
380  // Use the default effects provided by the system, such as translation, scaling, and opacity.
381  pageTransition() {
382    // Set the duration of the entrance animation to 1000 ms, in the purpose of matching the duration of the exit animation of the other page.
383    PageTransitionEnter({ duration: 1000 })
384      .slide(SlideEffect.Left)
385    // Set the duration of the exit animation to 1200 ms, in the purpose of matching the duration of the entrance animation of the other page.
386    PageTransitionExit({ duration: 1200 })
387      .translate({ x: 100.0, y: 100.0 })
388      .opacity(0)
389  }
390}
391```
392
393![pageTransition2](figures/pageTransition2.gif)
394
395### Example 2: Setting Translation Effects for Entrance and Exit
396
397Method 1: Configure the various translation effects provided, with the system language layout mode set to right-to-left (RTL).
398
399```ts
400// index.ets
401import { router } from '@kit.ArkUI'
402
403@Entry
404@Component
405struct PageTransitionExample {
406  @State scale1: number = 1
407  @State opacity1: number = 1
408
409  build() {
410    Column() {
411      Button("Page 1").onClick(() => {
412        router.pushUrl({
413          url: "pages/page1"
414        })
415      })
416        .width(200)
417        .height(60)
418        .fontSize(36)
419      Text("START")
420        .fontSize(36)
421        .textAlign(TextAlign.Center)
422    }
423    .scale({ x: this.scale1 })
424    .opacity(this.opacity1)
425    .height("100%")
426    .width("100%")
427    .justifyContent(FlexAlign.Center)
428  }
429
430  // Customization method 2: Use the default effects provided by the system, such as translation, scaling, and opacity.
431  pageTransition() {
432    // Set the entrance animation.
433    PageTransitionEnter({ duration: 200 })
434      .slide(SlideEffect.START)
435    // Set the exit animation.
436    PageTransitionExit({ delay: 100 })
437      .slide(SlideEffect.START) //Left
438  }
439}
440```
441
442```ts
443// page1.ets
444import { router } from '@kit.ArkUI'
445
446@Entry
447@Component
448struct PageTransitionExample {
449  @State scale1: number = 1
450  @State opacity1: number = 1
451
452  build() {
453    Column() {
454      Button("Page 2").onClick(() => {
455        router.pushUrl({
456          url: "pages/Index"
457        })
458      })
459        .width(200)
460        .height(60)
461        .fontSize(36)
462      Text("END")
463        .fontSize(36)
464        .textAlign(TextAlign.Center)
465    }
466    .scale({ x: this.scale1 })
467    .opacity(this.opacity1)
468    .height("100%")
469    .width("100%")
470    .justifyContent(FlexAlign.Center)
471  }
472
473  // Customization method 2: Use the default effects provided by the system, such as translation, scaling, and opacity.
474  pageTransition() {
475    PageTransitionEnter({ duration: 200 })
476      .slide(SlideEffect.END) //Right
477    PageTransitionExit({ delay: 100 })
478      .slide(SlideEffect.END) //Right
479  }
480}
481
482```
483
484![pageTransition1](figures/pageRTL.gif)
485
486Method 2: Use the system's default entrance and exit effects, with the system language layout mode set to right-to-left (RTL).
487
488```ts
489// index.ets
490import { router } from '@kit.ArkUI'
491
492@Entry
493@Component
494struct PageTransitionExample {
495  @State scale1: number = 1
496  @State opacity1: number = 1
497
498  build() {
499    Column() {
500      Button("Page 1").onClick(() => {
501        router.pushUrl({
502          url: "pages/page1"
503        })
504      })
505        .width(200)
506        .height(60)
507        .fontSize(36)
508    }
509    .scale({ x: this.scale1 })
510    .opacity(this.opacity1)
511    .height("100%")
512    .width("100%")
513    .justifyContent(FlexAlign.Center)
514  }
515}
516```
517
518```ts
519// page1.ets
520import { router } from '@kit.ArkUI'
521
522@Entry
523@Component
524struct PageTransitionExample {
525  @State scale1: number = 1
526  @State opacity1: number = 1
527
528  build() {
529    Column() {
530      Button("Page 2").onClick(() => {
531        router.pushUrl({
532          url: "pages/Index"
533        })
534      })
535        .width(200)
536        .height(60)
537        .fontSize(36)
538    }
539    .scale({ x: this.scale1 })
540    .opacity(this.opacity1)
541    .height("100%")
542    .width("100%")
543    .justifyContent(FlexAlign.Center)
544  }
545}
546```
547
548![pageTransition1](figures/pageRTL2.gif)
549