有个问题,我从Navigation()跳转到NavDestination(),这个时候我调用NaviDestination的pop方法返回Navigation(),这个时候Navigation调用哪个生命周期?
aboutToApear() ,onPageShow()都不会调用,鸿蒙没有提供类似的回调方法(至少我没找到),但可以有另外的写法,如下
import { promptAction, uiObserver } from '@kit.ArkUI';
import appUtils from '../utils/loginUtils/AppUtils'
import { ZRouter } from '@hzw/zrouter';
import { LoginBean, LoginBeanKey, } from '@taole/basecommon';
import createGtCapCha4Util, { GtCaptCha4Util } from '../utils/loginUtils/sdk4/GtCaptCha4Util';
@Entry
@Component
struct Index {
aboutToAppear(): void {
uiObserver.on('navDestinationUpdate', (info) => {
switch (info.state) {
case uiObserver.NavDestinationState.ON_WILL_APPEAR:
console.error(info.name.toString(), 'onWillAppear');
break
case uiObserver.NavDestinationState.ON_APPEAR:
console.error(info.name.toString(), 'onAppear')
break
case uiObserver.NavDestinationState.ON_WILL_SHOW:
console.error(info.name.toString(), 'onWillshow')
break
case uiObserver.NavDestinationState.ON_SHOWN:
console.error(info.name.toString(), 'onShow')
break
case uiObserver.NavDestinationState.ON_WILL_HIDE:
console.error(info.name.toString(), 'onWillHide')
break
case uiObserver.NavDestinationState.ON_HIDDEN:
console.error(info.name.toString(), 'onHidden')
break
case uiObserver.NavDestinationState.ON_WILL_DISAPPEAR:
console.error(info.name.toString(), 'onWillDisappear')
break
case uiObserver.NavDestinationState.ON_DISAPPEAR:
console.error(info.name.toString(), 'onDisappear')
break
case uiObserver.NavDestinationState.ON_BACKPRESS:
console.error(info.name.toString(), 'onBackpress')
break
}
})
}
build() {
Navigation(ZRouter.getNavStack()) {
Column({ space: 20 }) {
}
.height('100%')
.width('100%')
}
}}
我们可以创建一个集合,当ON_APPEAR调用的时候,在集合中增加一个info.name.toString(),当ON_DISAPPEAR调用的时候,就在集合中移除一个info.name.toString()。当集合为0的时候,此时NavDestination就全部被disappear了,就表示返回到了Navigation界面。