HarmonyOS Navigator跳转后TextTimer控件无法倒计时?

使用router方式跳转时倒计时可正常使用,使用Navigator方式跳转后只显示59不倒计时。

我们采用的这种跳转方式

static pushPathByName(appPathStack: NavPathStack, name: string, param?: Object, onPop?: Callback<PopInfo>, animated?: boolean){
  try {
    appPathStack.pushPathByName(name,param,onPop,animated)
  } catch (err) {
    console.debug("pushPathByName error "+err)
  }
}

是不是因为跳转方式的原因

阅读 577
1 个回答

该方式跳转暂不支持,建议使用下述测试Demo的跳转方式。

// Navigator.ets
@Entry
@Component
struct NavigatorExample {
  @State active: boolean = false
  @State name: NameObject = { name: 'news' }

  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
      Navigator({ target: 'pages/TextTimerPage', type: NavigationType.Push }) {
        Text('Go to ' + this.name.name + ' page')
          .width('100%').textAlign(TextAlign.Center)
      }.params(new TextObject(this.name)) // 传参数到Detail页面

      Navigator() {
        Text('Back to previous page').width('100%').textAlign(TextAlign.Center)
      }.active(this.active)
      .onClick(() => {
        this.active = true
      })
    }.height(150).width(350).padding(35)
  }
}

interface NameObject {
  name: string;
}

class TextObject {
  text: NameObject;

  constructor(text: NameObject) {
    this.text = text;
  }
}



//TextTimerPage
@Entry
@Component
struct TextTimerPage {
  @State elapsedTime: number =0;
  textTimerController: TextTimerController = new TextTimerController()

  onPageShow(): void {
    this.textTimerController.start()

  }

  build() {
    NavDestination(){
      Row(){
        TextTimer({isCountDown:true,count:59000,controller:this.textTimerController})
          .format("ss")
          .fontColor(Color.Brown)
          .onTimer((utc: number, elapsedTime: number)=>{
            this.elapsedTime =elapsedTime
          })
        Text("ss")
          .fontSize(15)
          .fontColor(Color.Orange)
      }
      .margin({top:25})
      .visibility(this.elapsedTime==59?Visibility.None:Visibility.Visible)
    }.hideTitleBar(true)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进