HarmonyOS TextTimer超过60s显示不符合预期

TextTimer超过60s显示不符合预期。

@Entry
@Component
struct TextTimerExample {
  textTimerController: TextTimerController = new TextTimerController()
  @State format: string = 'ss.SS'

  build() {
    Column() {
      TextTimer({ isCountDown: true, count: 70000, controller: this.textTimerController })
        .format(this.format)
        .fontColor(Color.Black)
        .fontSize(50)
        .onTimer((utc: number, elapsedTime: number) => {
          console.info('textTimer notCountDown utc is:' + utc + ', elapsedTime: ' + elapsedTime)
        })
      Row() {
        Button("start").onClick(() => {
          this.textTimerController.start()
        })
        Button("pause").onClick(() => {
          this.textTimerController.pause()
        })
        Button("reset").onClick(() => {
          this.textTimerController.reset()
        })
      }
    }
  }
}
HarmonyOS
6天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

示例参考如下:

class MyTextTimerModifier implements ContentModifier<TextTimerConfiguration> {
  constructor() {
  }

  applyContent(): WrappedBuilder<[TextTimerConfiguration]> {
    return wrapBuilder(buildTextTimer)
  }
}

@Builder
function buildTextTimer(config: TextTimerConfiguration) {
  Column() {
    Stack({ alignContent: Alignment.Center }) {
      Circle({ width: 150, height: 150 })
        .fill(config.started ? (config.isCountDown ? 0xFF232323 : 0xFF717171) : 0xFF929292)
      Column() {
        Text(
          Math.max(config.count / 1000 - config.elapsedTime / 100, 0).toFixed(2) + ""
        ).fontColor(Color.White)
      }
    }
  }
}

@Entry
@Component
struct Index {
  @State count: number = 70000
  @State myTimerModifier: MyTextTimerModifier = new MyTextTimerModifier()
  countDownTextTimerController: TextTimerController = new TextTimerController()
  countUpTextTimerController: TextTimerController = new TextTimerController()

  build() {
    Row() {
      Column() {
        TextTimer({ isCountDown: true, count: this.count, controller: this.countDownTextTimerController })
          .contentModifier(this.myTimerModifier)
          .onTimer((utc: number, elapsedTime: number) => {
            console.info('textTimer onTimer utc is:' + utc + ', elapsedTime: ' + elapsedTime)
          })
          .margin(10)
        Row() {
          Button("start").onClick(() => {
            this.countDownTextTimerController.start()
            this.countUpTextTimerController.start()
          }).margin(10)
          Button("pause").onClick(() => {
            this.countDownTextTimerController.pause()
            this.countUpTextTimerController.pause()
          }).margin(10)
          Button("reset").onClick(() => {
            this.countDownTextTimerController.reset()
            this.countUpTextTimerController.reset()
          }).margin(10)
        }.margin(20)
      }.width('100%')
    }.height('100%')
  }
}
分享
微博
QQ
微信
回复
5天前
相关问题
HarmonyOS BlendMode显示效果不符合预期
140浏览 • 1回复 待解决
点击事件冒泡不符合预期
858浏览 • 1回复 待解决
RichText组件font标签size属性不符合预期
2047浏览 • 1回复 待解决
HarmonyOS 不符合UI组件语法
168浏览 • 1回复 待解决
HarmonyOS 3DES的key长度不符合
54浏览 • 1回复 待解决
HarmonyOS TextTimer60秒倒计时显示成00
246浏览 • 1回复 待解决
HarmonyOS 轨迹线样式和预期不符
327浏览 • 1回复 待解决
HarmonyOS Text添加动画效果与预期不符
264浏览 • 1回复 待解决
HarmonyOS TextTimer如何设置起始时间
41浏览 • 1回复 待解决
HarmonyOS TextTimer倒计时问题
205浏览 • 1回复 待解决