欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > 【每日学点鸿蒙知识】Web嵌套滚动体验、拷贝传递 ArrayBuffer异常问题、ObjectLink 的属性传递、构建读取参数

【每日学点鸿蒙知识】Web嵌套滚动体验、拷贝传递 ArrayBuffer异常问题、ObjectLink 的属性传递、构建读取参数

2025/4/22 9:11:46 来源:https://blog.csdn.net/sjw890821sjw/article/details/144770112  浏览:    关键词:【每日学点鸿蒙知识】Web嵌套滚动体验、拷贝传递 ArrayBuffer异常问题、ObjectLink 的属性传递、构建读取参数
1、HarmonyOS Web嵌套滚动体验差?

商品详情页,嵌套滚动的时候父容器往下滑的过程中,惯性传不到WebView里面,但是从webView往上滑的时候,惯性能传递到父布局。

import web_webview from '@ohos.web.webview';@Entry
@Component
export struct WebScrollerDemo {private scrollTouchDown: boolean = false;private webTouchDown: boolean = false;private scrolling: boolean = false;private scroller: Scroller = new Scroller()controller: web_webview.WebviewController = new web_webview.WebviewController();build() {Scroll(this.scroller) {Column() {Text("Scroll Area").width("100%").height(400).backgroundColor(0X330000FF).fontSize(16).textAlign(TextAlign.Center)Web({controller: this.controller,src: "https://www.huawei.com/s?id=1778113237500106256&wfr=spider&for=pc",}).height("100%").width("100%").nestedScroll({scrollForward: NestedScrollMode.PARENT_FIRST,scrollBackward: NestedScrollMode.SELF_FIRST}).onTouch((event: TouchEvent) => {if (event.type == TouchType.Down) {this.webTouchDown = true;} else if (event.type == TouchType.Up) {this.webTouchDown = false;}})}.width("100%")}.onTouch((event: TouchEvent) => {if (event.type == TouchType.Down) {this.scrollTouchDown = true;} else if (event.type == TouchType.Up) {this.scrollTouchDown = false;}}).onScrollFrameBegin((offset: number, state: ScrollState) => {let yOffset: number = this.scroller.currentOffset().yOffsetif (this.scrolling && offset > 0) {if (yOffset >= 400) { // 400为上面Text组件高度this.controller.scrollBy(0, offset)return { offsetRemain: 0 }} else if (yOffset + offset > 400) {this.controller.scrollBy(0, yOffset + offset - 400)return { offsetRemain: 400 - yOffset }}}return { offsetRemain: offset }}).onScrollStart(() => {if (this.scrollTouchDown && !this.webTouchDown) {this.scrolling = true;}}).onScrollStop(() => {this.scrolling = false;}).edgeEffect(EdgeEffect.Spring).backgroundColor('#DCDCDC').scrollBar(BarState.On).width('100%').height('100%')}
}
2、HarmonyOS taskpool.SequenceRunner 拷贝传递 ArrayBuffer 出现异常?

利用 ImageReceiver 从摄像头获取帧 ArrayBuffer,然后将 ArrayBuffer 传入线程池做耗时算法分析。由于 ArrayBuffer 后续还需要使用,所以设置了 setCloneList 希望拷贝传递。代码如下:

private runner: taskpool.SequenceRunner = new taskpool.SequenceRunner();let task = new taskpool.Task(run, buffer, width, height);
task.setCloneList([buffer]);
let result = await this.runner.execute(task);

发现报如下错误:10200006 An exception occurred during serialization, taskpool: failed to serialize arguments.

如果注释掉@Concurrent,就会报10200006 An exception occurred during serialization, taskpool: failed to serialize arguments.

import taskpool from '@ohos.taskpool';@Concurrent
function printArgs(args: number): number {console.info("printArgs: " + args);return args;
}taskpool.execute(printArgs, 100).then((value: Object) => { // 100: test numberconsole.info("taskpool result: " + value);
});
3、HarmonyOS ObjectLink 的属性怎么传递给子组件?

ObjectLink 的属性怎么传递给子组件

参考下ObjectLink的文档,直接在子组件中用ObjectLink修饰你需要的数据:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-observed-and-objectlink-V5#%E8%A7%82%E5%AF%9F%E5%8F%98%E5%8C%96

4、HarmonyOSApp构建是否可以区分读取脚本参数并将脚本参数注入到BuildProfile文件中?

App构建需要区分多环境,目前依赖配置多个Target并在target上配置buildProfileField字段来区别 是否可以配置构建脚本,读取shell参数将shell参数注入到代码构建中,像xxxx构建的Gradle一样写Groovy语言,构建时动态修改构建脚本,注入不同参数值

可以通过hook以及插件上下文实现动态配置,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-hvigor-config-ohos-guide-V5

5、HarmonyOS Web组件grayscale属性设置未能生效?

设置了web组件的grayscale属性,用于为当前组件添加灰度效果,经过测试未能产生效果。

import web_webview from '@ohos.web.webview'@Entry
@Component
struct WebComponent {controller: web_webview.WebviewController = new web_webview.WebviewController()build() {Column() {Web({ src: 'www.huawei.com', controller: this.controller }).grayscale(0.5)}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词