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().yOffset
if (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 number
console.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#观察变化
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)
}
}
}