ohos_circle_indicator:基于OpenHarmony的UI组件库项目

用户可快速为Tabs/Swiper容器添加多样化指示器效果。该项目提供圆形、长条、三角等多种风格,支持自定义UI属性与交互逻辑,适配HSP场景,使用简单且扩展性强。【此简介由AI生成】

Branch1Tags0
FilesLast commitLast update
2 years ago
1 year ago
2 years ago
2 years ago
5 months ago
2 years ago
2 years ago
1 year ago
4 years ago
3 years ago
2 years ago
2 years ago
5 months ago
5 months ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago

CircleIndicator

Introduction

CircleIndicator is a UI component library that provides a variety of indicators for the Tabs and Swiper containers.

Effect

Circle indicator

Line indicator

All the APIs with blengthb

Triangle indicator

Icon indicator

Tabs indicator with center view

Fixed-position Tabs indicator

Fixed-position Tabs indicator (capsule style)

Fixed-position Tabs indicator (with a badge)

Scrollable Tabs indicator

Scrollable Tabs indicator (water drop slider)

Scrollable Tabs indicator (with the first tab fixed)

Titles indicator

How to Install

ohpm install @ohos/circleindicator

For details about the OpenHarmony ohpm environment configuration, see OpenHarmony HAR.

How to Use

The library provides a variety of indicators. The following uses TriangularIndicator as an example. The usage is the same for other indicators.

  1. Instantiate TabsController and a Model object, and add a member of the number type to record the subscript of the current page.
private controller: TabsController = new TabsController()
@State model: TriangularModel = new TriangularModel(this.controller)
@State itemIndex: number = 0
  1. Set UI properties through the Model object and add required callbacks.
aboutToAppear() {
 this.model
   .setReverse(true)
   .setLineHeight(4)
   .setTriangleHeight(10)
   .setLineColor("#e94220")
   .setBackgroundColor("#eeeeee")
   .setChangeListener((itemIndex: number) => {
     console.info("change page to " + this.data[itemIndex])
   })
}
  1. Place the Indicator component next to the Tabs component. Note that the native bar needs to be closed. Listen for the touch events of the Tabs component to process the sliding logic in a unified manner.
build() {
 Column() {
   TriangularIndicator({ itemIndex: $itemIndex, count: this.data.length, model: this.model })
   Tabs({ index: this.itemIndex, controller: this.controller }) {
     ...
   }
   .barWidth(0)
   .onTouch((event: TouchEvent) => {
     this.model.notifyTouch(event, this.itemIndex)
   })
 }.padding({ top: 40 })
 .backgroundColor("#eeeeee")
}

For details, see the implementation on the sample page of the open-source library.

Available APIs

model: TriangularModel = new TriangularModel(this.controller) // (Replace TriangularModel with the Model class you use)

API Description
model.setWidth(width: Length,context?:common.UIAbilityContext) Sets the indicator width.
NOTE
1. The value of width does not support percent notation.
2. Currently, different logic is used to process float.json resources and ets variables without units. The former is processed as px, and the latter is processed as vp. To avoid ambiguity, you are advised to add the unit (px, vp, or fp) for the resource when passing a parameter in the $r('app.float.[id]') format.
model.setHeight(height: Length,context?:common.UIAbilityContext) Sets the indicator height.
setBackgroundColor(backgroundColor: ResourceColor) Sets the background color of the indicator.
model.notifyTouch(event: TouchEvent, index: number) Sends a notification related to a touch event.
model.setChangeListener(callback: (index: number) => void) Adds a listener for the page transition.
model.getHeight() Obtain indicator height.
model.getWidth() Obtain indicator width.
getBackgroundColor() Obtain the background color of the indicator.
model.getChangeListener() Get page switching monitoring.

About obfuscation

  • Code obfuscation, please seeCode Obfuscation
  • If you want the circleindicator library not to be obfuscated during code obfuscation, you need to add corresponding exclusion rules in the obfuscation rule configuration file obfuscation-rules.txt:
-keep
./oh_modules/@ohos/circleindicator

Constraints

This project has been verified in the following version:

  • DevEco Studio: NEXT Beta1-5.0.3.806, SDK: API12 Release(5.0.0.66)

Adaptation for HSP scenario:

In all the indicator configuration classes, all the APIs with length as the input parameter are added with an optional parameter context. In the HSP scenario, you must pass in the correct context so that the resource can be obtained.

In non-HSP scenarios, the context parameter can be left unspecified.

Project Directory

|---- CircleIndicator
|     |---- entry  # Sample code
|     |---- library  # CircleIndicator library
|           |----src
|                 |----main
|                       |----ets
|                             |----components
|                                   |----CircleIndicator.ets # Indicator implementation
|                                   |----utils # Utility for UI drawing
|           |---- index.ets  # External APIs
|     |---- README.md  # Readme
|     |---- README_zh.md  # Readme

How to Contribute

If you find any problem when using the project, submit an Issue or a PR.

License

This project is licensed under Apache License 2.0.

Introduction

用户可快速为Tabs/Swiper容器添加多样化指示器效果。该项目提供圆形、长条、三角等多种风格,支持自定义UI属性与交互逻辑,适配HSP场景,使用简单且扩展性强。【此简介由AI生成】

Customize your domain