HarmonyOS 开发-应用新功能引导实现案例

介绍

本文介绍如何使用high_light_guide三方库完成应用新版本功能导航。通过高亮区域与蒙版背景的明暗度对比,让用户快速锁定重点功能,了解版本变更和业务入口。

效果图预览

使用说明

  1. 点击页面上对应按钮或空白区域进入下一个提示,直至提示完成。

实现思路

  1. 在需要使用的页面引入high_light_guide库中的引导页组件。
typescript 复制代码
   // 引入引导页组件
   import { HighLightGuideBuilder, HighLightGuideComponent, Controller, GuidePage, HighLightShape, RectF } from '@ohos/high_light_guide';
  1. 初始化引导页构建类,通过addHighLight绑定对应id组件的高光。此案例设定3个addGuidePage引导页配置,每个配置里添加引导页组件。
typescript 复制代码
   // 初始化引导页构建类
   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));
   }
  1. 设定各setHighLightIndicator里的引导层布局组件
typescript 复制代码
   @Builder
   private firstIndicator() {
     ... // 引导层内容
   }
  1. 计算id为test组件处于页面中的位置,为引导说明组件做位置控制。

    使用@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);
   })
  1. 添加引导页布局,通过HighLightGuideComponent的onReady回调参数controller控制引导层初始化显示。
typescript 复制代码
   build() {
     Stack() {
       ...
       // 添加引导页布局
       HighLightGuideComponent({
         highLightContainer: this.HighLightComponent, // 引导页覆盖时的内容布局插槽
         currentHLIndicator: null, // 引导页的引导层插槽
         builder: this.builder, // 引导页的通用配置构建类
         onReady: (controller: Controller) => { // 引导页准备好的回调,获取引导页控制器
           this.controller = controller;
           this.controller.show();
         }
       })
       ...
     }
   }
  1. 自定义Builder,设定底层页面基础布局。

    @Builder
    private HighLightComponent() {
      Column() {
        ... // 布局内容
      }
      .alignItems(HorizontalAlign.Start)
      .width('100%')
      .height('100%');
    }
    
  2. 通过controller控制引导层跳转和销毁。

typescript 复制代码
   this.controller.showPage(1);// 跳转第二个引导页
   this.controller.showPage(2);// 跳转第三个引导页
   this.controller.remove();   // 移除引导层

高性能知识点

不涉及

工程结构&模块类型

   highlightguide                               // har类型
   |---src\main\ets\pages
   |   |---Index.ets                            // 功能引导页面

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ......

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ......

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ......

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题

2.性能优化方向

3.架构方向

4.鸿蒙开发系统底层方向

5.鸿蒙音视频开发方向

6.鸿蒙车载开发方向

7.鸿蒙南向开发方向

相关推荐
仍有未知等待探索17 分钟前
Linux 传输层UDP
linux·运维·udp
没有余地 EliasJie19 分钟前
Windows Ubuntu下搭建深度学习Pytorch训练框架与转换环境TensorRT
pytorch·windows·深度学习·ubuntu·pycharm·conda·tensorflow
zeruns80224 分钟前
如何搭建自己的域名邮箱服务器?Poste.io邮箱服务器搭建教程,Linux+Docker搭建邮件服务器的教程
linux·运维·服务器·docker·网站
卑微求AC24 分钟前
(C语言贪吃蛇)16.贪吃蛇食物位置随机(完结撒花)
linux·c语言·开发语言·嵌入式·c语言贪吃蛇
北城青31 分钟前
WebRTC Connection Negotiate解决
运维·服务器·webrtc
技术无疆34 分钟前
【Python】Streamlit:为数据科学与机器学习打造的简易应用框架
开发语言·人工智能·python·深度学习·神经网络·机器学习·数据挖掘
qxqxa35 分钟前
cfg80211是怎么配置无线设备的AP的?
网络·驱动开发
Hugo_McQueen1 小时前
pWnos1.0 靶机渗透 (Perl CGI 的反弹 shell 利用)
linux·服务器·网络安全
浊酒南街1 小时前
吴恩达深度学习笔记:卷积神经网络(Foundations of Convolutional Neural Networks)2.7-2.8
人工智能·深度学习·神经网络
疯狂的大狗1 小时前
docker进入正在运行的容器,exit后的比较
运维·docker·容器