HarmonyOS 对于Scroll内有Tabs,Tabs内有List,list和外部的Scroll嵌套滚动有什么比较方便的办法实现呢?

HarmonyOS 对于Scroll内有Tabs,Tabs内有List,list和外部的Scroll嵌套滚动有什么比较方便的办法实现呢?

HarmonyOS
2024-10-08 11:11:59
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa
@Entry  
@Component  
struct page240429110107050 {  
  @State message: string = 'Hello World'  
  @State arr: number[] = []  
  private touchDown: boolean = false;  
  private listTouchDown: boolean = false;  
  private scrolling: boolean = false;  
  private scroller: Scroller = new Scroller()  
  private listScroller: Scroller = new Scroller()  
  @Styles  
  listCard() {  
    .backgroundColor(Color.White)  
    .height(72)  
    .width("100%")  
    .borderRadius(12)  
  }  
  build() {  
    Scroll(this.scroller) {  
      Column() {  
        Text("Scroll Area")  
          .width("100%")  
          .height("400")  
          .backgroundColor('#0080DC')  
          .textAlign(TextAlign.Center)  
        Tabs({ barPosition: BarPosition.Start }) {  
          TabContent() {  
            List({ space: 10, scroller: this.listScroller }) {  
              ForEach(this.arr, (item: number) => {  
                ListItem() {  
                  Text("item" + item)  
                    .fontSize(16)  
                }.listCard()  
              }, (item: number) => item.toString())  
            }.width("100%")  
            .edgeEffect(EdgeEffect.Spring)  
            .nestedScroll({  
              scrollForward: NestedScrollMode.PARENT_FIRST,  
              scrollBackward: NestedScrollMode.SELF_FIRST  
            })  
            .onTouch((event: TouchEvent) => {  
              if (event.type == TouchType.Down) {  
                this.listTouchDown = true;  
              } else if (event.type == TouchType.Up) {  
                this.listTouchDown = false;  
              }  
            })  
          }.tabBar("Tab1")  
          TabContent() {  
          }.tabBar("Tab2")  
        }  
        .vertical(false)  
        .height("100%")  
      }.width("100%")  
    }  
    .onTouch((event: TouchEvent) => {  
      if (event.type == TouchType.Down) {  
        this.touchDown = true;  
      } else if (event.type == TouchType.Up) {  
        this.touchDown = false;  
      }  
    })  
    .onScrollFrameBegin((offset: number, state: ScrollState) => {  
      if (this.scrolling && offset > 0) {  
        let yOffset: number = this.scroller.currentOffset().yOffset  
        if (yOffset >= 400) {  
          this.listScroller.scrollBy(0, offset)  
          return { offsetRemain: 0 }  
        } else if (yOffset + offset > 400) {  
          this.listScroller.scrollBy(0, yOffset + offset - 400)  
          return { offsetRemain: 400 - yOffset }  
        }  
      }  
      return { offsetRemain: offset }  
    })  
    .onScrollStart(() => {  
      if (this.touchDown && !this.listTouchDown) {  
        this.scrolling = true;  
      }  
    })  
    .onScrollStop(() => {  
      this.scrolling = false;  
    })  
    .edgeEffect(EdgeEffect.Spring)  
    .backgroundColor('#DCDCDC')  
    .scrollBar(BarState.Off)  
    .width('100%')  
    .height('100%')  
  }  
  aboutToAppear() {  
    for (let i = 0; i < 30; i++) {  
      this.arr.push(i)  
    }  
  }  
}
分享
微博
QQ
微信
回复
2024-10-08 17:04:59
相关问题
HarmonyOS scrolllist滚动冲突
260浏览 • 1回复 待解决
scrolllist嵌套滑动
1342浏览 • 1回复 待解决
HarmonyOS scroll嵌套List不能整体滑动
284浏览 • 1回复 待解决
refresh + scroll+list嵌套问题
268浏览 • 1回复 待解决
tabs结合scroll实现吸顶效果
1214浏览 • 1回复 待解决
如何实现scrolllist单边回弹效果
381浏览 • 1回复 待解决
HarmonyOS Scroll 嵌套 RelativeContainer 问题
354浏览 • 1回复 待解决
HarmonyOS Tabs组件嵌套Tabs组件问题
615浏览 • 1回复 待解决
HarmonyOS Scroll嵌套RelativeContainer 问题
211浏览 • 1回复 待解决
HarmonyOS Web组件List嵌套使用问题
137浏览 • 1回复 待解决