1e41f4b71Sopenharmony_ci# Enter/Exit Transition 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciYou can use [transition](../reference/apis-arkui/arkui-ts/ts-transition-animation-component.md), a basic component transition API, to animate the process in which a component enters or exits the view. You can even use it with [TransitionEffect](../reference/apis-arkui/arkui-ts/ts-transition-animation-component.md#transitioneffect10) to up your animation game. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci **Table 1** Transition effect APIs 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci| API| Description| Animation| 10e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 11e41f4b71Sopenharmony_ci| IDENTITY | Disables the transition effect.| None.| 12e41f4b71Sopenharmony_ci| OPACITY | Applies the default opacity transition effect.| The component enters by changing the opacity from 0 to 1 and exits by changing the opacity from 1 to 0.| 13e41f4b71Sopenharmony_ci| SLIDE | Applies a sliding transition effect.| The component enters by sliding in from the left edge of the window and exits by sliding out from the right edge of the window.| 14e41f4b71Sopenharmony_ci| translate | Applies a translation transition effect.| The component enters by moving from the position set by the **translate** API to the default position (value **0**), and exits by moving from the default position (value **0**) to the position set by the **translate** API.| 15e41f4b71Sopenharmony_ci| rotate | Applies a rotation transition effect.| The component enters by rotating from the position set by the **rotate** API to the default position (value **0**), and exits by rotating from the default position (value **0**) to the position set by the **rotate** API.| 16e41f4b71Sopenharmony_ci| opacity | Applies an opacity transition effect.| The component enters by changing the opacity from the set value to **1** (default value) and exits by changing the opacity from **1** to the set value.| 17e41f4b71Sopenharmony_ci| move | Applies a transition effect by specifying which edge the component slides in and out of through [TransitionEdge](../reference/apis-arkui/arkui-ts/ts-transition-animation-component.md#transitionedge10).| The component enters by sliding in from the edge specified by **TransitionEdge** and exits by sliding out of the same edge.| 18e41f4b71Sopenharmony_ci| asymmetric | Applies an asymmetric transition effect.<br>- **appear**: enter transition effect.<br>- **disappear**: exit transition effect.| The component enters by applying the transition effect specified by **appear** and exits by applying the transition effect specified by **disappear**.| 19e41f4b71Sopenharmony_ci| combine | Combines with other transition effects.| The component enters and exits by combing with other transition effects.| 20e41f4b71Sopenharmony_ci| animation | Defines the animation settings for the transition effect.<br>- If animation settings are not specified here, the animation settings of **animateTo** will be used.<br>- Animation settings cannot be configured through the **animation** API of the component.<br>- The **onFinish** callback of the **animation** parameter in **TransitionEffect** does not take effect.| The API call sequence is from top to bottom. This means that the **animation** settings of **TransitionEffect** at the upper level also take effect on **TransitionEffect** at the lower level .| 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci1. Create a **TransitionEffect** object. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci ```ts 26e41f4b71Sopenharmony_ci // The component enters by applying all enter transition effects and exits by applying all exit transition effects. 27e41f4b71Sopenharmony_ci // Define the animation settings for each transition effect. 28e41f4b71Sopenharmony_ci private effect: object = 29e41f4b71Sopenharmony_ci TransitionEffect.OPACITY // Apply an opacity transition effect. As the animation API is not called here, the animation settings of animateTo are used. 30e41f4b71Sopenharmony_ci // Apply a scaling transition effect and specify springMotion (0.6, 1.2) as the curve. 31e41f4b71Sopenharmony_ci .combine(TransitionEffect.scale({ x: 0, y: 0 }).animation({ curve: curves.springMotion(0.6, 1.2) })) 32e41f4b71Sopenharmony_ci // Apply a rotation transition effect, whose animation settings follow TransitionEffect above, that is, springMotion (0.6, 1.2). 33e41f4b71Sopenharmony_ci .combine(TransitionEffect.rotate({ angle: 90 })) 34e41f4b71Sopenharmony_ci // Apply a translation transition effect, whose animation settings follow TransitionEffect above, that is, springMotion (0.6, 1.2). 35e41f4b71Sopenharmony_ci .combine(TransitionEffect.translate({ x: 150, y: 150 }) 36e41f4b71Sopenharmony_ci // Apply a move transition effect and specify springMotion as the curve. 37e41f4b71Sopenharmony_ci .combine(TransitionEffect.move(TransitionEdge.END)).animation({curve: curves.springMotion()})) 38e41f4b71Sopenharmony_ci // Apply an asymmetric transition effect. As the animation API is not called here, the animation settings follow TransitionEffect above, that is, springMotion. 39e41f4b71Sopenharmony_ci .combine(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0, y: 0 }), TransitionEffect.rotate({ angle: 90 }))); 40e41f4b71Sopenharmony_ci ``` 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci2. Set the transition effects to the component by calling [transition](../reference/apis-arkui/arkui-ts/ts-transition-animation-component.md). 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci ```ts 45e41f4b71Sopenharmony_ci Text('test') 46e41f4b71Sopenharmony_ci .transition(this.effect) 47e41f4b71Sopenharmony_ci ``` 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci3. Add or delete the component to trigger transition. 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci ```ts 52e41f4b71Sopenharmony_ci @State isPresent: boolean = true; 53e41f4b71Sopenharmony_ci ... 54e41f4b71Sopenharmony_ci if (this.isPresent) { 55e41f4b71Sopenharmony_ci Text('test') 56e41f4b71Sopenharmony_ci .transition(this.effect) 57e41f4b71Sopenharmony_ci } 58e41f4b71Sopenharmony_ci ... 59e41f4b71Sopenharmony_ci // Control the addition or deletion of the component. 60e41f4b71Sopenharmony_ci // Method 1: Place the control variable in the animateTo closure. In this case, the transition effect for which the animation API is not call will follow the animation settings of animateTo. 61e41f4b71Sopenharmony_ci animateTo({ curve: curves.springMotion() }, () => { 62e41f4b71Sopenharmony_ci this.isPresent = false; 63e41f4b71Sopenharmony_ci }) 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci // Method 2: Directly delete or add the component. In this case, the transition effects follow the animation settings specified by animation. 66e41f4b71Sopenharmony_ci this.isPresent = false; 67e41f4b71Sopenharmony_ci ``` 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci Below is the complete sample code and effect. In the example, the transition is triggered by deleting or adding a component. It can also be triggered by changing the variables in the **animateTo** closure. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci```ts 73e41f4b71Sopenharmony_ciimport { curves } from '@kit.ArkUI'; 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci@Entry 76e41f4b71Sopenharmony_ci@Component 77e41f4b71Sopenharmony_cistruct TransitionEffectDemo { 78e41f4b71Sopenharmony_ci @State isPresent: boolean = false; 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci // Step 1: Create a TransitionEffect object. 81e41f4b71Sopenharmony_ci private effect: TransitionEffect = 82e41f4b71Sopenharmony_ci // Apply the default opacity transition effect and specify springMotion (0.6, 0.8) as the curve. 83e41f4b71Sopenharmony_ci TransitionEffect.OPACITY.animation({ curve: curves.springMotion(0.6, 0.8) }) 84e41f4b71Sopenharmony_ci // Combine with a scale transition effect, whose animation settings follow TransitionEffect above, that is, springMotion(0.6, 0.8). 85e41f4b71Sopenharmony_ci .combine(TransitionEffect.scale({ x: 0, y: 0 })) 86e41f4b71Sopenharmony_ci // Apply a rotation transition effect, whose animation settings follow TransitionEffect above, that is, springMotion(0.6, 0.8). 87e41f4b71Sopenharmony_ci .combine(TransitionEffect.rotate({ angle: 90 })) 88e41f4b71Sopenharmony_ci // Apply a translation transition effect, whose animation settings are specified by animation, which is springMotion(). 89e41f4b71Sopenharmony_ci .combine(TransitionEffect.translate({ y: 150 }).animation({ curve: curves.springMotion() })) 90e41f4b71Sopenharmony_ci // Apply a movement transition effect, whose animation settings follow TransitionEffect above, that is, springMotion(). 91e41f4b71Sopenharmony_ci .combine(TransitionEffect.move(TransitionEdge.END)) 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci build() { 94e41f4b71Sopenharmony_ci Stack() { 95e41f4b71Sopenharmony_ci if (this.isPresent) { 96e41f4b71Sopenharmony_ci Column() { 97e41f4b71Sopenharmony_ci Text('ArkUI') 98e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 99e41f4b71Sopenharmony_ci .fontSize(20) 100e41f4b71Sopenharmony_ci .fontColor(Color.White) 101e41f4b71Sopenharmony_ci } 102e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 103e41f4b71Sopenharmony_ci .width(150) 104e41f4b71Sopenharmony_ci .height(150) 105e41f4b71Sopenharmony_ci .borderRadius(10) 106e41f4b71Sopenharmony_ci .backgroundColor(0xf56c6c) 107e41f4b71Sopenharmony_ci // Step 2: Set the transition effects to the component through the transition API. 108e41f4b71Sopenharmony_ci .transition(this.effect) 109e41f4b71Sopenharmony_ci } 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci // Border 112e41f4b71Sopenharmony_ci Column() 113e41f4b71Sopenharmony_ci .width(155) 114e41f4b71Sopenharmony_ci .height(155) 115e41f4b71Sopenharmony_ci .border({ 116e41f4b71Sopenharmony_ci width: 5, 117e41f4b71Sopenharmony_ci radius: 10, 118e41f4b71Sopenharmony_ci color: Color.Black 119e41f4b71Sopenharmony_ci }) 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci // Step 3: Add or delete the component to trigger transition. 122e41f4b71Sopenharmony_ci Button('Click') 123e41f4b71Sopenharmony_ci .margin({ top: 320 }) 124e41f4b71Sopenharmony_ci .onClick(() => { 125e41f4b71Sopenharmony_ci this.isPresent = !this.isPresent; 126e41f4b71Sopenharmony_ci }) 127e41f4b71Sopenharmony_ci } 128e41f4b71Sopenharmony_ci .width('100%') 129e41f4b71Sopenharmony_ci .height('60%') 130e41f4b71Sopenharmony_ci } 131e41f4b71Sopenharmony_ci} 132e41f4b71Sopenharmony_ci``` 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ciWhen adding transition effects to multiple components, you can configure different **delay** values in animation parameters of these effects so that the components exit one by one. 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci```ts 142e41f4b71Sopenharmony_ciconst ITEM_COUNTS = 9; 143e41f4b71Sopenharmony_ciconst ITEM_COLOR = '#ED6F21'; 144e41f4b71Sopenharmony_ciconst INTERVAL = 30; 145e41f4b71Sopenharmony_ciconst DURATION = 300; 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci@Entry 148e41f4b71Sopenharmony_ci@Component 149e41f4b71Sopenharmony_cistruct Index1 { 150e41f4b71Sopenharmony_ci @State isGridShow: boolean = false; 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci private dataArray: number[] = new Array(ITEM_COUNTS); 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci aboutToAppear(): void { 155e41f4b71Sopenharmony_ci for (let i = 0; i < ITEM_COUNTS; i++) { 156e41f4b71Sopenharmony_ci this.dataArray[i] = i; 157e41f4b71Sopenharmony_ci } 158e41f4b71Sopenharmony_ci } 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci build() { 161e41f4b71Sopenharmony_ci Stack() { 162e41f4b71Sopenharmony_ci if (this.isGridShow) { 163e41f4b71Sopenharmony_ci Grid() { 164e41f4b71Sopenharmony_ci ForEach(this.dataArray, (item: number, index: number) => { 165e41f4b71Sopenharmony_ci GridItem() { 166e41f4b71Sopenharmony_ci Stack() { 167e41f4b71Sopenharmony_ci Text((item + 1).toString()) 168e41f4b71Sopenharmony_ci } 169e41f4b71Sopenharmony_ci .size({ width: 50, height: 50 }) 170e41f4b71Sopenharmony_ci .backgroundColor(ITEM_COLOR) 171e41f4b71Sopenharmony_ci .transition(TransitionEffect.OPACITY 172e41f4b71Sopenharmony_ci .combine(TransitionEffect.scale({ x: 0.5, y: 0.5 })) 173e41f4b71Sopenharmony_ci // Add delay to the transition of each grid cell so that the grid cells exit one by one. 174e41f4b71Sopenharmony_ci .animation({ duration: DURATION, curve: Curve.Friction, delay: INTERVAL * index })) 175e41f4b71Sopenharmony_ci .borderRadius(10) 176e41f4b71Sopenharmony_ci } 177e41f4b71Sopenharmony_ci // When the grid cells exit, the exit transition effect does not take effect if the transition effect is not added to the parent component. 178e41f4b71Sopenharmony_ci // Here the parent component of the grid cells is configured to always display with a 0.99 opacity when the cells exit. In this way, the transition effect of grid cells is not affected. 179e41f4b71Sopenharmony_ci .transition(TransitionEffect.opacity(0.99)) 180e41f4b71Sopenharmony_ci }, (item: number) => item.toString()) 181e41f4b71Sopenharmony_ci } 182e41f4b71Sopenharmony_ci .columnsTemplate('1fr 1fr 1fr') 183e41f4b71Sopenharmony_ci .rowsGap(15) 184e41f4b71Sopenharmony_ci .columnsGap(15) 185e41f4b71Sopenharmony_ci .size({ width: 180, height: 180 }) 186e41f4b71Sopenharmony_ci // When the grid cells exit, the exit transition effect does not take effect if the transition effect is not added to the parent component. 187e41f4b71Sopenharmony_ci // Here the parent component of the grid cells is configured to always display with a 0.99 opacity when the cells exit. In this way, the transition effect of grid cells is not affected. 188e41f4b71Sopenharmony_ci .transition(TransitionEffect.opacity(0.99)) 189e41f4b71Sopenharmony_ci } 190e41f4b71Sopenharmony_ci } 191e41f4b71Sopenharmony_ci .size({ width: '100%', height: '100%' }) 192e41f4b71Sopenharmony_ci .onClick(() => { 193e41f4b71Sopenharmony_ci animateTo({ 194e41f4b71Sopenharmony_ci duration: DURATION + INTERVAL * (ITEM_COUNTS - 1), 195e41f4b71Sopenharmony_ci curve: Curve.Friction 196e41f4b71Sopenharmony_ci }, () => { 197e41f4b71Sopenharmony_ci this.isGridShow = !this.isGridShow; 198e41f4b71Sopenharmony_ci }) 199e41f4b71Sopenharmony_ci }) 200e41f4b71Sopenharmony_ci } 201e41f4b71Sopenharmony_ci} 202e41f4b71Sopenharmony_ci``` 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci 205