HarmonyOS 嵌套滚动冲突

Scroll->Tabs->List嵌套时,给List添加nestedScroll无法解决滚动冲突

Scroll包含Tabs,Tabs中的TabContent包含List,此时给List增加:

.nestedScroll({
  scrollForward: NestedScrollMode.PARENT_FIRST,
  scrollBackward: NestedScrollMode.SELF_FIRST
})
  • 1.
  • 2.
  • 3.
  • 4.

期望Scroll和List同时只有一个滚动,但是现在是两个都可以响应滚动。

HarmonyOS
2024-12-24 17:12:38
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

请参考demo

@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%")

        // .height(300)

        // Column()
        // .width('100%')
        // .height(1000)
      }.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.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
分享
微博
QQ
微信
回复
2024-12-24 19:23:52
相关问题
HarmonyOS scroll和list滚动冲突
1127浏览 • 1回复 待解决
滑动嵌套事件冲突处理
1025浏览 • 0回复 待解决
HarmonyOS Scroll嵌套web手势冲突
683浏览 • 1回复 待解决
HarmonyOS list嵌套MapComponent滑动冲突
593浏览 • 1回复 待解决
HarmonyOS Refresh组件嵌套滑动冲突问题
1920浏览 • 1回复 待解决
HarmonyOS Scroll中嵌套List滑动事件冲突
816浏览 • 1回复 待解决
Web和List嵌套手势冲突问题
1691浏览 • 1回复 待解决
HarmonyOS Web嵌套滚动体验差
816浏览 • 1回复 待解决
基于webView的嵌套滚动
1037浏览 • 1回复 待解决
如何实现嵌套滚动技术
2073浏览 • 1回复 待解决
页面和列表嵌套滚动,实现列表吸顶
2264浏览 • 1回复 待解决