本文介绍如何使用high_light_guide三方库完成应用新版本功能导航。通过高亮区域与蒙版背景的明暗度对比,让用户快速锁定重点功能,了解版本变更和业务入口。
使用说明
// 引入引导页组件
import { HighLightGuideBuilder, HighLightGuideComponent, Controller, GuidePage, HighLightShape, RectF } from '@ohos/high_light_guide';
// 初始化引导页构建类
aboutToAppear() {
this.builder = new HighLightGuideBuilder()
.alwaysShow(true)
.addGuidePage(GuidePage.newInstance()// 设定第一处提示
.setEverywhereCancelable(true)// 允许点击任意处关闭
.addHighLightWithOptions('test', HighLightShape.CIRCLE, options)// 为id为test的组件绑定特定形状高光
.setHighLightIndicator(this.firstIndicator.bind(this))
.setEnterAnimation(this.enterAnimatorParam)
.setExitAnimation(this.exitAnimatorParam))
.addGuidePage(GuidePage.newInstance()// 设定第二处提示
.setHighLightIndicator(this.secondIndicator)
.setEnterAnimation(this.enterAnimatorParam)
.setExitAnimation(this.exitAnimatorParam))
.addGuidePage(GuidePage.newInstance()// 设定第三处提示
.setEverywhereCancelable(false)
.setHighLightIndicator(this.thirdIndicator));
}
@Builder
private firstIndicator() {
... // 引导层内容
}
使用@Provide装饰器和@Consume装饰器:与后代组件双向同步,将基础页面布局中id为test组件的坐标传递给引导页。
@Provide PosX: number = 0;
@Provide PosY: number = 0;
@State firstIndicatorHeight: number = 0;
@Builder
private firstIndicator() {
... // 引导层内容:提示文字等
}
.onAreaChange((oldValue: Area, newValue: Area) => {
this.firstIndicatorHeight = Number(newValue.height);// 获取此引导组件的高度
})
// 此案例x坐标为id为test组件宽度的一半
// y坐标为id为test组件相对于屏幕顶部的距离与自身高度的差值
.position({ x: this.PosX, y: this.PosY - this.firstIndicatorHeight })
@Consume PosX: number;
@Consume PosY: number;
GridItem() {
...
}
.onAreaChange((oldValue: Area, newValue: Area) => {
this.PosX = Number(newValue.width) / RADIUS;// 此案例需获取此组件宽度的一半,作为演示
this.PosY = Number(newValue.globalPosition.y);
})
build() {
Stack() {
...
// 添加引导页布局
HighLightGuideComponent({
highLightContainer: this.HighLightComponent, // 引导页覆盖时的内容布局插槽
currentHLIndicator: null, // 引导页的引导层插槽
builder: this.builder, // 引导页的通用配置构建类
onReady: (controller: Controller) => { // 引导页准备好的回调,获取引导页控制器
this.controller = controller;
this.controller.show();
}
})
...
}
}
欢迎大家关注公众号<程序猿百晓生>,可以了解到一下知识点。
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.鸿蒙版性能优化指南
.......
@Builder
private HighLightComponent() {
Column() {
... // 布局内容
}
.alignItems(HorizontalAlign.Start)
.width('100%')
.height('100%');
}
this.controller.showPage(1);// 跳转第二个引导页
this.controller.showPage(2);// 跳转第三个引导页
this.controller.remove(); // 移除引导层
不涉及
highlightguide // har类型
|---src\main\ets\pages
| |---Index.ets // 功能引导页面
如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。