本示例通过模拟下载场景介绍如何将Native的进度信息实时同步到ArkTS侧。

使用说明
Progress({ value: this.progress, total: 100, type: ProgressType.Ring })
.width($r("app.integer.progress_size"))
.height($r("app.integer.progress_size"))
.animation({ duration: NativeProgressNotifyConstants.PROGRESS_ANIMATION_DURATION, curve: Curve.Ease })
.style({ strokeWidth: 15 })
naitiveprogressnotify.startDownload((data: number) => {
this.progress = data;
console.log("[NativeProgressNotify]progress:" + this.progress);
})
std::thread downloadThread(downloadTask, asyncContext);
downloadThread.detach();
while (context && context->progress < 100) {
context->progress += 1;
napi_acquire_threadsafe_function(tsfn);
napi_call_threadsafe_function(tsfn, (void *)context, napi_tsfn_blocking);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
napi_create_int32(arg->env, arg->progress, &progress);
napi_call_function(arg->env, nullptr, jsCb, 1, &progress, nullptr);
本例中,在Native侧使用子线程执行下载任务,从而避免对主线程资源的占用,能有效提升性能
verifycode // har类型
|---constants
| |---NativeProgressNotifyContants.ets // 常量
|---view
| |---NativeProgressNotify.ets // 视图层
不涉及
为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05
https://qr21.cn/FV7h05如何快速入门:https://qr21.cn/FV7h05

开发基础知识:https://qr21.cn/FV7h05

基于ArkTS 开发:https://qr21.cn/FV7h05

https://qr21.cn/FV7h05
https://qr21.cn/FV7h051.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向

腾讯T10级高工技术,安卓全套VIP课程全网免费送:https://qr21.cn/D2k9D5