HarmonyOS List组件在bindSheet半模态里面进行加载,监听底部的onReachEnd不生效

我看相关文档设置了 底部和顶部的方法。

但是我进入程序页面的时候 list还未滑动到底部onReachEnd方法就加载了。

手动滑动到底部的时候也未触发该方法, 我这个list再bindSheet半模态里面进行加载的。


HarmonyOS
2024-10-28 09:26:50
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

参考以下代码:

class MyDataSource implements IDataSource {  
  private listeners: DataChangeListener[] = [];  
  registerDataChangeListener(listener: DataChangeListener): void {  
    if (this.listeners.indexOf(listener) < 0) {  
      console.info('add listener');  
      this.listeners.push(listener);  
    }  
  }  
  
  unregisterDataChangeListener(listener: DataChangeListener): void {  
    const pos = this.listeners.indexOf(listener);  
    if (pos >= 0) {  
      console.info('remove listener');  
      this.listeners.splice(pos, 1);  
    }  
  }  
  private dataArray: string[] = [];  
  
  public totalCount(): number {  
    return this.dataArray.length;  
  }  
  
  public getData(index: number): string {  
    return this.dataArray[index];  
  }  
  notifyDataAdd(index: number): void {  
    this.listeners.forEach(listener => {  
      listener.onDataAdd(index);  
    })  
  }  
  
  
  public addData(index: number, data: string): void {  
    this.dataArray.splice(index, 0, data);  
    this.notifyDataAdd(index);  
  }  
  
  public pushData(data: string): void {  
    this.dataArray.push(data);  
    this.notifyDataAdd(this.dataArray.length - 1);  
  }  
}  
@Entry  
@Component  
struct GovernmentMapPage {  
  @State message: string = '政务地图';  
  @State isShow: boolean = true  
  @State sheetHeight: number = -1;  
  @State showDragBar: boolean = false;  
  private data: MyDataSource = new MyDataSource();  
  
  aboutToAppear() {  
    for (let i = 0; i <= 100; i++) {  
      this.data.pushData(`Hello ${i}`)  
    }  
  }  
  @Builder  
  myBuilder() {  
    Column() {  
      List(){  
        LazyForEach(this.data, (item: string) => {  
          ListItem() {  
            Row() {  
              Text(item).fontSize(50)  
                .onAppear(() => {  
                  console.info("appear:" + item)  
                })  
            }.margin({ left: 10, right: 10 })  
          }  
        }, (item: string) => item)  
      }  
      .nestedScroll({scrollForward:NestedScrollMode.SELF_FIRST, scrollBackward:NestedScrollMode.PARENT_FIRST})  
      .edgeEffect(EdgeEffect.None)  
      .onReachEnd(()=>{  
        console.log("onReachEnd")  
      })  
      .onReachStart(()=>{  
        console.log("onReachStart")  
      })  
    }  
    .width('100%')  
    .height('100%')  
  
  }  
  build() {  
    Column() {  
      Button("政务地图")  
        .onClick(() => {  
          this.isShow = true  
        })  
        .fontSize(20)  
        .margin(10)  
        .bindSheet($$this.isShow, this.myBuilder(), {  
          height: this.sheetHeight,  
          dragBar: this.showDragBar,  
          backgroundColor: Color.Blue,  
          onAppear: () => {  
            console.log("BindSheet onAppear.")  
          },  
          onDisappear: () => {  
            console.log("BindSheet onDisappear.")  
          }  
        })  
    }  
    .justifyContent(FlexAlign.Center)  
    .width('100%')  
    .height('100%')  
  }  
}
分享
微博
QQ
微信
回复
2024-10-28 15:21:09
相关问题
HarmonyOS bindSheet模态弹窗
341浏览 • 1回复 待解决
基于bindSheet模态弹窗
1050浏览 • 1回复 待解决
List组件initialIndex属性设置生效
2284浏览 • 1回复 待解决
嵌套组件中Scroll生效
2183浏览 • 1回复 待解决
HarmonyOS 模态转场
29浏览 • 1回复 待解决