本示例通过模拟下载场景介绍如何将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.info("[NativeProgressNotify]progress:" + this.progress);
})
std::thread downloadThread(downloadTask, asyncContext);
downloadThread.detach();
欢迎大家关注公众号<程序猿百晓生>,可以了解到一下知识点。
1.OpenHarmony开发基础
2.OpenHarmony北向开发环境搭建
3.鸿蒙南向开发环境的搭建
4.鸿蒙生态应用开发白皮书V2.0 & V3.0
5.鸿蒙开发面试真题(含参考答案)
6.TypeScript入门学习手册
7.OpenHarmony 经典面试题(含参考答案)
8.OpenHarmony设备开发入门【最新版】
9.沉浸式剖析OpenHarmony源代码
10.系统定制指南
11.【OpenHarmony】Uboot 驱动加载流程
12.OpenHarmony构建系统--GN与子系统、部件、模块详解
13.ohos开机init启动流程
14.鸿蒙版性能优化指南
.......
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 // 视图层
不涉及
如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。