DEV Community

HarmonyOS
HarmonyOS

Posted on

Detecting the End of Navigation Pop Animation

Read the original article:Detecting the End of Navigation Pop Animation

Question

When using NavPathStack.pop(), how can I detect when the pop animation has completed?

Short Answer

You can use the onNavBarStateChange() callback to detect when the system navigation animation completes. This works even with the default system transitions, without requiring custom animations. You can find the code example below;

onNavBarStateChange((flag) => {
  if (flag) {
    console.log('NavBar', 'Navigation Index change, now is show');
  } else {
    console.log('NavBar', 'Navigation Index change, now is hide');
  }
});
Enter fullscreen mode Exit fullscreen mode

Applicable Scenarios

Useful when you need to perform an action right after the navigation transition finishes (e.g., cleaning up state, starting a new process, etc.) and you're using the system-provided default animation in NavPathStack.pop().

Reference Link

https://developer.huawei.com/consumer/en/doc/harmonyos-references/ts-basic-components-navigation#onnavbarstatechange9

Written by Emincan Ozcan

Top comments (0)