当前位置:网站首页>Circulaindicator component, which makes the indicator style more diversified
Circulaindicator component, which makes the indicator style more diversified
2022-07-25 15:49:00 【InfoQ】
CircleIndicator Introduce













namespace TriangularIndicator {
export class Model {
// Set indicator height
mHeight: number = 18
// Set indicator width
mWidth: number = lpx2px(720)
// Set the indicator background color
mBackgroundColor: string
// Too many fields , Omit here
// Fields set And get Method , Here only height Field as an example
public getHeight(): number {
return this.mHeight
}
public setHeight(height: number): Model {
this.mHeight = height
return this
}
// Touch event interception
onPageTouch: (event: TouchEvent, currentIndicator: number) => void
public notifyTouch(event: TouchEvent, currentIndex: number) {
this.onPageTouch(event, currentIndex)
}
// Set constructor
private tabsController: TabsController
(tabsController: TabsController) {
this.tabsController = tabsController
}
// Page switching monitoring
indexChange: (itemIndex: number) => void
public setChangeListener(callback: (index: number) => void): Model{
this.indexChange = callback
return this
}
}
@Component
struct TriangularIndicator {
// obtain TriangularIndicator example
@State model: TriangularIndicator.Model = new TriangularIndicator.Model(null)
// Initialize the indicator current index
@Link @Watch("itemIndexChange") itemIndex: number
// Set the total number of indicators
@State count: number = 0
// And then realize itemIndexChange、aboutToAppear、onTouch、getOffset Method , The implementation here does not show
// And then build The method describes UI structure
build() {
Column() {
Rect({ width: this.model.mWidth, height: this.model.mLineHeight }).fill(this.model.mLineColor)
Polygon()
.points(this.model.mReverse ?
[[px2vp(this.model.mWidth) / (this.count * 2) - this.model.mTriangleWidth / 2, this.model.mLineHeight - this.model.mYOffset],
[px2vp(this.model.mWidth) / (this.count * 2), this.model.mLineHeight + this.model.mTriangleHeight - this.model.mYOffset],
[px2vp(this.model.mWidth) / (this.count * 2) + this.model.mTriangleWidth / 2, this.model.mLineHeight - this.model.mYOffset]] :
[[px2vp(this.model.mWidth) / (this.count * 2) - this.model.mTriangleWidth / 2, -this.model.mYOffset],
[px2vp(this.model.mWidth) / (this.count * 2), -this.model.mTriangleHeight - this.model.mYOffset],
[px2vp(this.model.mWidth) / (this.count * 2) + this.model.mTriangleWidth / 2, -this.model.mYOffset]])
.offset(this.model.mStartInterpolator ?
{ x: px2vp(this.model.mWidth) / this.count * (this.itemIndex - this.model.mStartInterpolator.interpolate(Math.abs(this.model.offs et / this.model.mWidth)) * Math.sign(this.model.offset)),
y: 0 } :
{ x: px2vp(this.model.mWidth) / this.count * (this.itemIndex - this.model.offset / this.model.mWidth),
y: 0 })
.fill(this.model.mLineColor)
.height(this.model.mHeight)
.width(this.model.mWidth)
}.width('100%').height(this.model.mHeight)
.backgroundColor(this.model.mBackgroundColor)
}
}
export default TriangularIndicator
CircleIndicator actual combat

private controller: TabsController = new TabsController()
@State model: TriangularIndicator.Model = new TriangularIndicator.Model(this.controller)
@State itemIndex: number = 0
aboutToAppear() {
this.model
.setReverse(true)
.setLineHeight(4)
.setTriangleHeight(10)
.setLineColor("#e94220")
.setBackgroundColor("#eeeeee")
.setChangeListener((itemIndex) => {
console.info("change page to " + this.data[itemIndex])
})
}
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")
}

边栏推荐
- Geogle colab notes 1-- run the.Py file on the cloud hard disk of Geogle
- Leetcode - 303 area and retrieval - array immutable (design prefix and array)
- 使用cpolar建立一个商业网站(如何购买域名)
- Redis distributed lock, it's really impossible without it
- LeetCode - 225 用队列实现栈
- 产品动态丨Android 13 高效适配全新升级
- 用GaussDB(for Redis)存画像,推荐业务轻松降本60%
- User defined annotation verification API parameter phone number
- 2021江苏省赛A. Array-线段树,维护值域,欧拉降幂
- Are you ready to break away from the "involution circle"?
猜你喜欢

Leetcode - 232 realize queue with stack (design double stack to realize queue)

Leetcode - 641 design cycle double ended queue (Design)*

JVM - classloader and parental delegation model

华为2023届提前批预热开始!左 神的程序代码面试指南终派上用场

GAMES101复习:线性代数

谷歌博客:采用多重游戏决策Transformer训练通用智能体

CVPR 2022 | in depth study of batch normalized estimation offset in network

Solve the vender-base.66c6fc1c0b393478adf7.js:6 typeerror: cannot read property 'validate' of undefined problem

十字链表的存储结构

LeetCode - 677 键值映射(设计)*
随机推荐
Leetcode - 303 area and retrieval - array immutable (design prefix and array)
Are you ready to break away from the "involution circle"?
SQL cultivation manual from scratch - practical part
2021HNCPC-E-差分,思维
Leetcode - 622 design cycle queue (Design)
MySQL—用户和权限管控
Leetcode - 232 realize queue with stack (design double stack to realize queue)
组件化和模块化
Matlab randInt, matlab randInt function usage "recommended collection"
「数字安全」警惕 NFT的七大骗局
Pytorch学习笔记--SEResNet50搭建
2021 Shanghai match-h-two point answer
Take you to create your first C program (recommended Collection)
LeetCode - 362 敲击计数器(设计)
Leetcode - 677 key value mapping (Design)*
华为2023届提前批预热开始!左 神的程序代码面试指南终派上用场
Pytorch学习笔记--常用函数总结3
Get the ask code corresponding to the key pressed by the keyboard
How to disable hosting when Flink SQL in flink-1.13.6 runs in yarn session mode
Window system black window redis error 20creating server TCP listening socket *: 6379: listen: unknown error19-07-28