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)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

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

HarmonyOS
2024-12-25 08:07:36
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

该方式跳转暂不支持,建议使用下述测试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)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
分享
微博
QQ
微信
回复
2024-12-25 10:52:59
相关问题
HarmonyOS TextTimer倒计时问题
896浏览 • 1回复 待解决
HarmonyOS TextTimer60秒倒计时显示成00
899浏览 • 1回复 待解决
HarmonyOS 倒计时天数
1249浏览 • 1回复 待解决
HarmonyOS 倒计时方法
1072浏览 • 1回复 待解决
HarmonyOS 实现倒计时功能
972浏览 • 1回复 待解决
HarmonyOS 页面倒计时怎么实现
682浏览 • 1回复 待解决
HarmonyOS 如何自动倒计时组件
1070浏览 • 1回复 待解决
HarmonyOS 60秒倒计时demo
814浏览 • 1回复 待解决
HarmonyOS Timer倒计时自定义
1242浏览 • 1回复 待解决
如何实现文本类型的倒计时
1522浏览 • 0回复 待解决
HarmonyOS 请问ArkTS如何实现倒计时功能?
34214浏览 • 8回复 待解决
如何实现一个倒计时器?
1308浏览 • 1回复 待解决
HarmonyOS TextTimer 计时器使用问题
1091浏览 • 1回复 待解决
提问
该提问已有0人参与 ,帮助了0人