【每日学点鸿蒙知识】List+Swipe滑动冲突、下拉刷新、编译错误定位、监听生命周期、上架应用市场要求
1、HarmonyOS List+Swipe+web滑动冲突?
在List中嵌套一个横向滑动的swipe,swipe嵌套一个web,此时设置手势优先的时,web无法和list进行联动交互
题原因可能是List组件嵌套Web组件产生了滑动冲突,这里可以使用触摸测试控制来规避此种情况:.hitTestBehavior(HitTestMode.Block)
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-gesture-events-multi-level-gesture-V5
2、HarmonyOS Webview如何实现下拉刷新效果?
可以使用pulltorefresh实现下拉刷新。参考链接如下:https://ohpm.openharmony.cn/#/cn/detail/@ohos%2Fpulltorefresh
3、通过Command line进行编译,如果发生错误,如何获取到错误信息,或者能获取到编译成功状态。
- 用hvigor进行编译的时候,可用加上各种命令,显示相关日志信息;
- -d(设置hvigor的日志级别为debug)
- –stacktrace(hvigor默认使能关闭打印所有异常的堆栈信息,如需开启在命令行后添加该选项)
- https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-hvigor-commandline-V5
- 执行命令编译时只会有返回码的:
- 构建成功:code 0
- 构建失败:code 1
- 基于不同平台采用对应方式获取该返回码就行。
4、HarmonyOS 普通对象怎么监听组件生命周期?
可以参考这个:https://gitee.com/openharmony/docs/blob/7ad8e708cebd3e4a43979e97de160da9c0533316/zh-cn/application-dev/reference/apis/js-apis-arkui-observer.md
//entryability.ets
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
interface Data {
window: window.Window
}
export default class EntryAbility extends UIAbility {
private window: window.Window | undefined = undefined
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
const that : EntryAbility = this
this.context.eventHub.on("getWindow", (data: Data) => {
if(that.window != undefined)
{
data.window = that.window
}
else {
hilog.info(0x0000, 'testTag', '%{public}s', 'that.subWindowStage == undefined');
}
})
}
onDestroy(): void {
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index2', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
// 获取应用主窗口。
let windowClass: window.Window = window.findWindow("observer0");
this.window = windowClass
windowStage.getMainWindow((err: BusinessError, data) => {
let errCode: number = err.code;
if (errCode) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
})
});
}
onWindowStageDestroy(): void {
}
}
//index2.ets
import common from '@ohos.app.ability.common';
import window from '@ohos.window';
import UIContext, { UIObserver } from '@ohos.ArkUI.UIContext';
import observer from '@ohos.ArkUI.observer';
import router from '@ohos.router';
interface Data11 {
window: window.Window | null
}
@Entry
@Component
struct Index2 {
private abilityContext: common.UIAbilityContext | null = null;
private uiContext: UIContext.UIContext | null = null
private context = getContext(this) as common.UIAbilityContext;
testFunc(info: observer.RouterPageInfo) {
console.log("[testFunc][UI-in-Pages] called by: Index2: " + `${info.index}` + ", name: " + `${info.name}` + ", path: " + `${info.path}` + ", state: " + `${info.state}`+ ",context: " + `${info.context}` );
}
aboutToAppear() {
console.log("[Test] aboutToAppear before createWindow");
this.abilityContext = getContext(this) as common.UIAbilityContext;
let data : Data11 = {
window: null
};
this.abilityContext.eventHub.emit("getWindow", data);
if (data.window) {
this.uiContext = data.window.getUIContext()
} else {
this.uiContext = null
}
router.getState()
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('这是Index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
Button('ObserverOn')
.margin({top:5})
.onClick(() => {
let observer: UIObserver | null = this.uiContext ? this.uiContext.getUIObserver() : null
if (observer) {
// 注册router页面监听,范围为当前UIContext
console.log("[Test] set observer to ON");
observer.on('routerPageUpdate', this.testFunc)
}
})
Button('ObserverOff')
.margin({top:5})
.onClick(() => {
let observer: UIObserver | null = this.uiContext ? this.uiContext.getUIObserver() : null
if (observer) {
// 注册router页面监听,范围为当前UIContext
console.log("[Test] set observer to OFF");
observer.off('routerPageUpdate', this.testFunc)
}
})
Button('pushUrl PageOne')
.margin({ top: 5})
.onClick(() => {
router.pushUrl({
url: 'pages/PageOne2',
})
})
}
.width('100%')
.height('100%')
.backgroundColor('#FFBFE5C5')
}
}
//PageOne2.ets
@Entry
@Component
struct PageOne2 {
@State message: string = '22222222222';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
5、HarmonyOS 设备指纹应用市场的上架SDK需要满足的条件?
需要在应用市场的上架SDK
1、IDE版本需要canary4sp1及以上版本
2、签名证书的帐号和上架SDK的帐号使用企业账号AGC申请发布证书,IDE增加签名指导:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-publish-app-V5