HarmonyOS 页面嵌套滑动时卡顿

我们这边有部分页面是存在嵌套滑动的,页面结构有两种类型:

(1)外层List,内层List,且内层List通过sticky属性设置了吸顶;

(2)外层List,内层Tab,Tab的元素是List。这两种结构在外层List页面滚动即将切换内层List滚动时,都会出现卡顿一下,无法一气呵成地滚到底,麻烦帮忙看下是什么问题

HarmonyOS
2025-01-09 15:03:33
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

示例参考如下:

@Entry
@Component
struct Index {

  private outerListScroller: ListScroller = new ListScroller();
  private innerListScroller: ListScroller = new ListScroller();
  private innerListScroller2: ListScroller = new ListScroller();
  private tabsController: TabsController = new TabsController();
  private topArr: number[] = Array(4).fill(1);
  private tabArr1: string[] = Array(20).fill("内层List第一个Tab的单元格");
  private tabArr2: string[] = Array(15).fill("内层List第二个Tab的单元格");

  build() {
    Column() {
      Text("我是标题区域") {

      }
      .backgroundColor(Color.Grey)
      .width('100%')
      .height(30)
      .textAlign(TextAlign.Center)

      List({scroller: this.outerListScroller}) {
        ForEach(this.topArr, (item: number) => {
          ListItem() {
            Text("我是外层List的单元格")
          }
          .width('100%')
          .height(300)
          .backgroundColor(Color.Brown)
          .margin({top: 10})
        })

        ListItem() {
          Stack({alignContent: Alignment.Top}) {
            Tabs({controller: this.tabsController}) {
              TabContent() {
                List({scroller: this.innerListScroller}) {
                  ForEach(this.tabArr1, (item: string) => {
                    ListItem() {
                      Text(item)
                        .width('80%')
                        .height(100)
                        .backgroundColor(Color.Orange)
                        .margin({top: 10})
                        .textAlign(TextAlign.Center)
                        .margin({left: '10%'})
                    }
                  })
                }
                .width('100%')
                .height('100%')
                .scrollBar(BarState.Off)
                .nestedScroll({
                  scrollForward: NestedScrollMode.PARENT_FIRST,
                  scrollBackward: NestedScrollMode.SELF_FIRST
                })
                .edgeEffect(EdgeEffect.None)
              }

              TabContent() {
                List({scroller: this.innerListScroller2}) {
                  ForEach(this.tabArr2, (item: string) => {
                    ListItem() {
                      Text(item)
                        .width('80%')
                        .height(60)
                        .backgroundColor(Color.Brown)
                        .margin({top: 10})
                        .textAlign(TextAlign.Center)
                        .margin({left: '10%'})
                    }
                  })
                }
                .width('100%')
                .height('100%')
                .scrollBar(BarState.Off)
                .nestedScroll({
                  scrollForward: NestedScrollMode.PARENT_FIRST,
                  scrollBackward: NestedScrollMode.SELF_FIRST
                })
                .edgeEffect(EdgeEffect.None)
              }
            }
            .barHeight(45)
            .barWidth(0)

            Row() {
              Text("点击第一个Tab")
                .width('50%')
                .height('100%')
                .onClick(() => {
                  this.tabsController.changeIndex(0);
                })
                .backgroundColor(Color.Yellow)
                .textAlign(TextAlign.Center)

              Text("点击第二个Tab")
                .width('50%')
                .height('100%')
                .onClick(() => {
                  this.tabsController.changeIndex(1);
                })
                .backgroundColor(Color.Pink)
                .textAlign(TextAlign.Center)
            }
            .width('100%')
            .height(45)
          }
        }

      }
      .onScrollFrameBegin((offset:number, state: ScrollState)=>{
        if(offset>0 && this.outerListScroller.isAtEnd()){
          this.innerListScroller.scrollBy(0,offset)
          this.innerListScroller2.scrollBy(0,offset)
          return {offsetRemain:0}
        }
        return {offsetRemain:offset}
      })
      .width('100%')
      .height('calc(100% - 30vp)')
      .edgeEffect(EdgeEffect.None)
      .scrollBar(BarState.Off)
    }
  }
}
  • 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.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
分享
微博
QQ
微信
回复
2025-01-09 17:13:02
相关问题
HarmonyOS List嵌套waterflow滑动
835浏览 • 1回复 待解决
HarmonyOS 页面滑动
673浏览 • 1回复 待解决
Web嵌套滑动怎么办?
886浏览 • 1回复 待解决
鸿蒙优化,如何检测线上
115浏览 • 0回复 待解决
HarmonyOS 横竖屏翻转
595浏览 • 1回复 待解决
HarmonyOS scroll嵌套list页面无法滑动
1107浏览 • 1回复 待解决
优化还有哪些方案
103浏览 • 0回复 待解决
HarmonyOS WebView加载H5
784浏览 • 1回复 待解决
如何滑动页面,让滑动速度变慢
135浏览 • 1回复 待解决
HarmonyOS LazyForEach多层级数据性能
862浏览 • 1回复 待解决
关于启动慢问题首帧分析
1090浏览 • 1回复 待解决
HarmonyOS Tabs组件嵌套滑动
988浏览 • 1回复 待解决