@Entry
@Component
struct Index {
@State message: string = 'Hello World';
@State mis: string[] = ["1", "2", "3", "4", "5"];
@State currentIndex: number = 0
private controller: TabsController = new TabsController();
@State misTabsIndex: number = 0;
@State fontColor: string = '#182431'
@State selectedFontColor: string = '#007DFF'
@Builder tabBuilder(index: number, name: string) {
Column() {
Text(name)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.fontSize(16)
.fontWeight(this.currentIndex === index ? 500 : 400)
.lineHeight(22)
.margin({ top: 17, bottom: 7 })
Divider()
.strokeWidth(2)
.color('#007DFF')
.opacity(this.currentIndex === index ? 1 : 0)
}.width('100%')
}
build() {
RelativeContainer() {
Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) {
ForEach(this.mis, (str: string, inx) => {
TabContent() {
if (this.currentIndex == inx) {
Column(){
Text(str)
}
.width("100%")
.height("100%")
.backgroundColor(Color.White)
}
}
.tabBar(this.tabBuilder(inx, 'green'))
.onWillShow(() => {
console.info("1234")
})
}, (str: string) => JSON.stringify(str))
}
.onChange((index)=>{
this.currentIndex = index
})
}
.height('100%')
.width('100%')
.backgroundColor("#f4f4f4")
}
}
TabContent进行循环显示,滑动导致出现短暂的空白,头部和TabContent中的内容延迟显示,请问怎么解决
这边有个demo,您可以尝试下
新增的onAnimationStart、onAnimationEnd和onGestureSwipe事件,本地测试不会感知到明显的延迟,
demo如下:
文档链接:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-tabs-V5\#事件