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

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

HarmonyOS
2024-10-08 11:11:59
447浏览
收藏 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)  
    }  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
分享
微博
QQ
微信
回复
2024-10-08 17:04:59


相关问题
scrolllist嵌套滑动
2580浏览 • 1回复 待解决
HarmonyOS scrolllist滚动冲突
1133浏览 • 1回复 待解决
HarmonyOS Scroll嵌套List滑动问题
797浏览 • 1回复 待解决
HarmonyOS Scroll+web+list嵌套滑行
656浏览 • 1回复 待解决
HarmonyOS scroll嵌套List不能整体滑动
1362浏览 • 1回复 待解决
HarmonyOS Scroll嵌套List滑动事件冲突
824浏览 • 1回复 待解决
HarmonyOS scroll嵌套list页面无法滑动
1437浏览 • 1回复 待解决
refresh + scroll+list嵌套问题
1068浏览 • 1回复 待解决
HarmonyOS Tabs横向Scroll滑动冲突
830浏览 • 1回复 待解决
tabs结合scroll实现吸顶效果
2462浏览 • 1回复 待解决
HarmonyOS list web scroll 联动
546浏览 • 1回复 待解决