Dialog-Type NavDestination Mask Animation Is Not Smooth
Symptom
When the default transition animation of NavDestinationMode.DIALOG is used, the following two issues occur:
-
When the mask background color is set on the page: When the page is popped, the mask does not disappear immediately. Instead, it disappears only after the content slides down and exits.

-
When the mask background color is set on the content area: The mask exits from top to bottom together with the content.

It is expected that the mask fades out while the content area exits downward.
Solution
Execute the background color animation in the onWillAppear and onWillDisappear lifecycle callbacks. The following is an example:
@Builder
export function DialogNavDestinationBuilder() {
DialogNavDestination();
}
@Component
export struct DialogNavDestination {
stack: NavPathStack = AppStorage.get<NavPathStack>('basicNavigationStack')!;
@State backColor: ResourceColor = '#00000000';
build() {
NavDestination() {
Stack() {
Text('Dialog')
.fontSize(44)
.backgroundColor(Color.White)
}
.width('100%')
.height('100%')
}
.hideTitleBar(true)
.backgroundColor(this.backColor)
.mode(NavDestinationMode.DIALOG)
.onWillAppear(() => {
// Fade in the mask on startup.
this.getUIContext().animateTo({ duration:450 }, () => {
this.backColor = '#66000000';
});
})
.onWillDisappear(() => {
// Fade out the mask on disappearance.
this.getUIContext().animateTo({ duration: 450 }, () => {
this.backColor = '#00000000';
});
})
}
} 
Router and Navigation Animation Conflict
Symptom
When router navigates to a navigation page, and navigation immediately pushes a NavDestination page in the aboutToAppear callback, the Page and the NavDestination page display animations at the same time, resulting in a poor effect.
Solution
Disable the animation of the push in aboutToAppear:
@Entry
@Component
struct NavigationPage {
navStack: NavPathStack = new NavPathStack();
aboutToAppear(): void {
AppStorage.setOrCreate<NavPathStack>('basicNavigationStack', this.navStack);
this.navStack.pushPath({ name: 'animation-BasicNavDestination' }, false); // Disable the animation for this push.
}
build() {
Navigation(this.navStack) {
// ...
}
}
} How to Implement a Shared Element Transition Between Navigation and NavDestination
Currently, only transitions between NavDestination components support the shared element transition effect. The system does not yet support the shared element effect for transitions between NavBar and NavDestination.
The shared element transition of NavDestination must be implemented together with the geometryTransition API, and the following conditions must be met:
For a sample, see Shared Element Transition.
Navigation Animation Anomaly After Setting zIndex on NavDestination
zIndex is used to modify the display level of a component. Setting this attribute on NavDestination overrides the level set by the system, which disrupts the animation. Therefore, setting zIndex on NavDestination is not recommended.
In addition, setting special attributes such as transition, geometryTransition, sharedTransition, and animation is also not recommended, as they may conflict with the system default animation. If your business requires these attributes, set them on the content node of NavDestination to achieve the same effect.
Page Is Blank When Multiple if Statements Are Used in the NavDestination Builder
Symptom
When multiple independent if statements are used in the builder specified by the navDestination property of Navigation to build NavDestination pages separately, some pages appear blank after navigation. For example, in the following usage, the page is blank when name is PageC:
@Entry
@Component
struct ExamplePage {
private stack: NavPathStack = new NavPathStack();
@Builder
pageMap(name: string) {
if (name === 'PageA') {
NavDestination()
.backgroundColor(Color.Red)
.title('PageA')
}
if (name === 'PageB') {
NavDestination()
.backgroundColor(Color.Green)
.title('PageB')
}
if (name === 'PageC') {
NavDestination()
.backgroundColor(Color.Blue)
.title('PageC')
}
}
build() {
Navigation(this.stack) {
Button("push PageA").onClick((event: ClickEvent) => {
this.stack.pushPathByName("PageA", null)
})
Button("push PageB").onClick((event: ClickEvent) => {
this.stack.pushPathByName("PageB", null)
})
Button("push PageC").onClick((event: ClickEvent) => {
this.stack.pushPathByName("PageC", null)
})
}
.navDestination(this.pageMap)
}
} Cause Analysis
The mechanism by which Navigation builds NavDestination is as follows:
- After the builder is executed, the first node serves as the root node, and the remaining nodes are mounted under this root node in code order. (Nodes that are siblings of the first node are mounted as child nodes.)
- When Navigation searches for the NavDestination node, it traverses downward from the root node along the first child node of each level until it finds the NavDestination. If the first child node at a certain level has no child nodes, the traversal terminates and cannot continue to search subsequent sibling nodes.
Each independent if statement produces an IfElseNode. The second and third IfElseNode nodes are mounted as sibling child nodes of the first IfElseNode, and the NavDestination is mounted under the IfElseNode whose condition is true.
-
When name === 'PageA', IfElseNode1 is true, and IfElseNode2 and IfElseNode3 are false. The resulting component tree is as follows:
IfElseNode1 ← Root node
├── NavDestination(PageA) ← IfElseNode1 is true, and NavDestination is the first child node of IfElseNode1
├── IfElseNode2 ← IfElseNode2 is false, no child nodes
└── IfElseNode3 ← IfElseNode3 is false, no child nodes
The Navigation component traverses from IfElseNode1 along the first child node and finds NavDestination(PageA), so the page displays normally.
-
When name === 'PageB', IfElseNode2 is true, and IfElseNode1 and IfElseNode3 are false, the resulting component tree is:
IfElseNode1 ← root node
├── IfElseNode2 ← IfElseNode2 is true
│ └── NavDestination(PageB)
└── IfElseNode3 ← IfElseNode3 is false, no child nodes
The Navigation component traverses from IfElseNode1 along the first child node: IfElseNode1 → IfElseNode2 → NavDestination(PageB), so the page displays normally.
-
When name === 'PageC', IfElseNode3 is true, and IfElseNode1 and IfElseNode2 are false, the resulting component tree is:
IfElseNode1 ← root node
├── IfElseNode2 ← IfElseNode2 is false, no child nodes (the first child node!)
└── IfElseNode3 ← IfElseNode3 is true
└── NavDestination(PageC) The Navigation component traverses IfElseNode1 along the first child node: IfElseNode1 → IfElseNode2 (no child nodes, traversal terminates), so it cannot find NavDestination(PageC), and the page is blank.
Solution
Change the multiple independent if statements in the builder to an if-else if-else judgment, which produces only one IfElseNode as the root node, ensuring that Navigation can traverse to find the NavDestination:
@Entry
@Component
struct NavDestinationSystemTransition {
// ...
@Builder
pageMap(name: string) {
if (name === 'Fade') {
Fade();
} else if (name === 'Explode') {
Explode();
} else if (name === 'SlideRight') {
SlideRight();
} else if (name === 'SlideBottom') {
SlideBottom();
} else {
Dest();
}
}
aboutToAppear(): void {
this.stack.pushPath({name: 'Dest'});
}
build() {
Navigation(this.stack) {
// ...
}
.navDestination(this.pageMap)
.hideNavBar(true)
}
}