若上述功能均未实现,则判断未使用骨架屏功能。
页面建议使用骨架屏功能,避免组件突然出现造成闪动。
@Entry
@Component
struct SkeletonScreen {
@State translageX: string = '-100%';
widthValue: number = 100;
heightValue: number = 28;
build() {
Stack() {
// 背景
Text()
.height(this.heightValue)
.width(this.widthValue)
.backgroundColor('rgba(220,220,220,1)');
// 动画
Text()
.height(this.heightValue)
.width(this.widthValue)
.translate({ x: this.translageX })
.onAppear(() => {
this.translageX = '100%';
})
.animation({
duration: 1500,
iterations: -1,
})
.linearGradient({
angle: 90,
colors: [
['rgba(255,255,255,0)', 0],
['rgba(255,255,255,1)', 0.5],
['rgba(255,255,255,0)', 1]
]
});
};
}
}