HarmonyOS List回弹问题

请提供List回弹demo。

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Excelsior_abit

demo如下:

@Builder
export function ListRefreshLoadBuilder(name: string, param: Object) {
  ListRefreshLoad()
}
@Component
struct ListRefreshLoad {
  @State arr: Array<number> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  @State refreshing: boolean = false;
  @State refreshOffset: number = 0;
  @State refreshState: RefreshStatus = RefreshStatus.Inactive;
  @State canLoad: boolean = false;
  @State isLoading: boolean = false;
  @Builder
  refreshBuilder() {
    Stack({ alignContent: Alignment.Bottom }) {
      // can use the refresh state to decide whether the progress component is exist or not.
      // in this case, the component is not exist otherwise in the pull down or refresh state
      if (this.refreshState != RefreshStatus.Inactive && this.refreshState != RefreshStatus.Done) {
        Progress({ value: this.refreshOffset, total: 64, type: ProgressType.Ring })
          .width(32).height(32)
          .style({ status: this.refreshing ? ProgressStatus.LOADING : ProgressStatus.PROGRESSING })
          .margin(10)
      }
    }.height("100%").width("100%")
  }
  @Builder
  footer() {
    Row() {
      LoadingProgress().height(32).width(48)
      Text("加载中")
    }.width("100%")
    .height(64)
    .justifyContent(FlexAlign.Center)
    // hidden this component when don't need to load
    .visibility(this.isLoading ? Visibility.Visible : Visibility.Hidden)
  }
  build() {
    NavDestination() {
      Refresh({ refreshing: $$this.refreshing, builder: this.refreshBuilder() }) {
        List() {
          ForEach(this.arr, (item: number) => {
            ListItem() {
              Text('' + item)
                .width('100%')
                .height(80)
                .fontSize(16)
                .textAlign(TextAlign.Center)
                .backgroundColor(0xFFFFFF)
            }.borderWidth(1)
          }, (item: string) => item)

          ListItem() {
            this.footer();
          }
        }
        .onScrollIndex((start: number, end: number) => {
          // when reach the end of list, trigger data load
          if (this.canLoad && end >= this.arr.length - 1) {
            this.canLoad = false;
            this.isLoading = true;
            // simulate trigger data load
            setTimeout(() => {
              for (let i = 0; i < 10; i++) {
                this.arr.push(this.arr.length);
                this.isLoading = false;
              }
            }, 700)
          }
        })
        .onScrollFrameBegin((offset: number, state: ScrollState) => {
          // loading can be triggered only when swipe up
          if (offset > 5 && !this.isLoading) {
            this.canLoad = true;
          }
          return { offsetRemain: offset };
        })
        .scrollBar(BarState.Off)
        // open the spring back of edge
        .edgeEffect(EdgeEffect.Spring, { alwaysEnabled: true })
      }
      .width('100%')
      .height('100%')
      .backgroundColor(0xDCDCDC)
      .onOffsetChange((offset: number) => {
        this.refreshOffset = offset;
      })
      .onStateChange((state: RefreshStatus) => {
        this.refreshState = state;
      })
      .onRefreshing(() => {
        // simulate refresh the data
        setTimeout(() => {
          this.refreshing = false;
        }, 2000)
      })
    }
  }
}
分享
微博
QQ
微信
回复
21h前
相关问题
如何实现scroll、list单边回弹效果
577浏览 • 1回复 待解决
如何将List回弹效果改为阴影效果
477浏览 • 1回复 待解决
HarmonyOS list组件问题
21浏览 • 1回复 待解决
HarmonyOS List的space问题
69浏览 • 1回复 待解决
HarmonyOS list数据加载问题
0浏览 • 0回复 待解决
HarmonyOS list滑动问题
842浏览 • 1回复 待解决
HarmonyOS list sticky相关问题
19浏览 • 1回复 待解决
HarmonyOS 列表List相关问题
473浏览 • 1回复 待解决
HarmonyOS List展示不全的问题
377浏览 • 1回复 待解决
HarmonyOS List item 刷新问题
815浏览 • 1回复 待解决
HarmonyOS List组件沉浸式问题
37浏览 • 1回复 待解决
List使用问题有哪些?
346浏览 • 1回复 待解决
如何关闭Swiper组件的回弹效果?
484浏览 • 1回复 待解决
HarmonyOS list 嵌套web滑动切换问题
509浏览 • 1回复 待解决
HarmonyOS List组件锚点问题咨询
4浏览 • 0回复 待解决
ArkTS UI的List和集合List冲突的问题
453浏览 • 1回复 待解决
HarmonyOS 列表展示list懒加载问题
657浏览 • 1回复 待解决