HarmonyOS 搜索结果页中,在loading中需要加载骨架屏,咨询合理的高性能方案

HarmonyOS 搜索结果页中,在loading中需要加载骨架屏,咨询合理的高性能方案

HarmonyOS
2024-08-30 10:08:03
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

可参考:

@Extend(Column) 
function commonStyle(width: string, color: Resource, opacity: number) { 
 .width(width) 
 .height('100%') 
 .backgroundColor(color) 
 .opacity(opacity) 
 .borderRadius(2) 
} 
 
@Entry 
@Component 
export default struct YangTest1Page { 
 @State arr: number[] = []; 
 @State ColumnBgColor: Resource = $r('app.color.gray_C0C0C0')//C0C0C0 
 @State ColumnOpacityCom: number = 0.5; 
 @State ListOpacityCom: number = 0.5; 
 @State listItemHeight: string = '20%' 
 
 startAnimation() { 
  animateTo({ 
   duration: 600, // 动画时长 
   tempo: 0.6, // 播放速率 
   curve: Curve.EaseInOut, // 动画曲线 
   delay: 200, // 动画延迟 
   iterations: -1, // 播放次数 
   playMode: PlayMode.Alternate, // 动画模式 
   onFinish: () => { 
    console.info('play end') 
   } 
  }, () => { 
   this.ListOpacityCom = 0.1; 
  }) 
 } 
 
 build() { 
  Column() { 
   List({ initialIndex: 0 }) { 
    ForEach(this.arr, (item: number) => { 
     ListItem() { 
      Column() { 
       Row() { 
        Column().commonStyle('50%', this.ColumnBgColor, this.ColumnOpacityCom) 
        Column().commonStyle('30%', this.ColumnBgColor, this.ColumnOpacityCom) 
       }.justifyContent(FlexAlign.SpaceBetween).width('100%').height('25%') 
 
       Blank().height('8%') 
       Row() { 
        Column().commonStyle('50%', this.ColumnBgColor, this.ColumnOpacityCom) 
        Column().commonStyle('30%', this.ColumnBgColor, this.ColumnOpacityCom) 
       }.justifyContent(FlexAlign.SpaceBetween).width('100%').height('10%') 
 
       Blank().height('8%') 
       Row() { 
        Column().layoutWeight(1) 
        Column().commonStyle('30%', this.ColumnBgColor, this.ColumnOpacityCom) 
       }.justifyContent(FlexAlign.SpaceBetween).width('100%').height('10%') 
 
       Blank().height('8%') 
       Row() 
        .height('12%') 
        .backgroundColor(this.ColumnBgColor) 
        .width('100%') 
        .opacity(this.ColumnOpacityCom) 
        .borderRadius(2) 
      }.margin({ top: '4%', bottom: '2%' }) 
     } 
     .width('90%') 
     .height(this.listItemHeight) 
    }, (item: number) => JSON.stringify(item)) 
   } 
   .alignListItem(ListItemAlign.Center) 
   .listDirection(Axis.Vertical) // 排列方向 
   .divider({ strokeWidth: 1, color: $r('app.color.gray_F4F5F7') }) // 每行之间的分界线 F4F5F7 
   .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果 
   .onScrollIndex((firstIndex: number, lastIndex: number) => { 
    console.info('first' + firstIndex) 
    console.info('last' + lastIndex) 
   }) 
   .scrollBar(BarState.Off) 
   .opacity(this.ListOpacityCom) 
 
   .width('100%') 
   .onAppear(() => { 
    this.startAnimation() 
   }) 
  }.width('100%').height('100%').padding({ top: 5 }) 
  .onAreaChange((oldValue: Area, newValue: Area) => { 
   const listHeight = Number(newValue.height) 
   const length = Math.round(listHeight / 120) 
   for (let i = 0; i < length; i++) { 
    this.arr.push(i) 
   } 
   this.listItemHeight = Math.floor(100 / length) + '%' 
  }) 
 } 
}
分享
微博
QQ
微信
回复
2024-08-30 17:51:06
相关问题
HarmonyOS 页面骨架
248浏览 • 0回复 待解决
如何实现ArkTS高性能编程?
463浏览 • 1回复 待解决
HarmonyOS 热修复技术方案咨询
191浏览 • 1回复 待解决
HarmonyOS 关于页面埋点方案咨询
438浏览 • 1回复 待解决
dolphindb怎么对查询结果分页?
2233浏览 • 1回复 待解决