HarmonyOS app商品详情页,根据提供的demo,如何解决Webview scrollForward正向滚动卡顿的问题

当前版本的app商品详情页,根据提供的demo,如何解决Webview scrollForward正向滚动卡顿的问题

如下demo

import web_webview from '@ohos.web.webview';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
export struct WebScrollerDemo {
  private scrollTouchDown: boolean = false;
  private webTouchDown: boolean = false;
  private scrolling: boolean = false;
  private scroller: Scroller = new Scroller()
  controller: web_webview.WebviewController = new web_webview.WebviewController();

  build() {
    Scroll(this.scroller) {
      Column() {
        Text("Scroll Area")
          .width("100%")
          .height(400)
          .backgroundColor(0X330000FF)
          .fontSize(16)
          .textAlign(TextAlign.Center)
        Web({
          controller: this.controller,
          src: "xxx",
        }).height("100%").width("100%")
          .nestedScroll({
            scrollForward: NestedScrollMode.PARENT_FIRST,
            scrollBackward: NestedScrollMode.SELF_FIRST
          })
          .onTouch((event: TouchEvent) => {
            if (event.type === TouchType.Down) {
              this.webTouchDown = true;
            } else if (event.type == TouchType.Up) {
              this.webTouchDown = false;
            }
            try {
              let pageHeight = this.controller.getPageHeight();
              console.log("testTag: Web pageHeight : " + pageHeight);
            } catch (error) {
              console.error(`testTag: Web ErrorCode: ${(error as BusinessError).code},  Message: ${(error as BusinessError).message}`);
            }
          })
      }.width("100%")
    }
    .onTouch((event: TouchEvent) => {
      if (event.type == TouchType.Down) {
        this.scrollTouchDown = true;
      } else if (event.type == TouchType.Up) {
        this.scrollTouchDown = false;
      }
      try {
        let pageHeight = this.controller.getPageHeight();
        console.log("testTag: Web pageHeight : " + pageHeight);
      } catch (error) {
        console.error(`testTag: Web ErrorCode: ${(error as BusinessError).code},  Message: ${(error as BusinessError).message}`);
      }
    })
    .onScrollFrameBegin((offset: number, state: ScrollState) => {
      let yOffset: number = this.scroller.currentOffset().yOffset
      if (this.scrolling && offset > 0) {
        if (yOffset >= 400) { // 400为上面Text组件高度
          this.controller.scrollBy(0, offset)
          return { offsetRemain: 0 }
        } else if (yOffset + offset > 400) {
          this.controller.scrollBy(0, yOffset + offset - 400)
          return { offsetRemain: 400 - yOffset }
        }
      }
      return { offsetRemain: offset }
    })
    .onScrollStart(() => {
      if (this.scrollTouchDown && !this.webTouchDown) {
        this.scrolling = true;
      }
    })
    .onScrollStop(() => {
      this.scrolling = false;
    })
    .edgeEffect(EdgeEffect.Spring)
    .backgroundColor('#DCDCDC')
    .scrollBar(BarState.On)
    .width('100%')
    .height('100%')
    .onAreaChange( (oldValue: Area, newValue: Area) => {
        console.log('testTag: ' + vp2px(newValue.height as number))
    })
  }
}
HarmonyOS
2025-01-09 15:58:10
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
fox280

onScrollFrameBegin使用规范有些要求,请按规范要求更改demo

若通过onScrollFrameBegin事件和scrollBy方法实现容器嵌套滚动,需设置子滚动节点的EdgeEffect为None。如Scroll嵌套List滚动时,List组件的edgeEffect属性需设置为EdgeEffect.None

参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-scroll-V5#onscrollframebegin9

分享
微博
QQ
微信
回复
2025-01-09 17:35:01
相关问题
商品详情页面的常规布局方式
1448浏览 • 1回复 待解决
如何启动应用系统设置详情页
2950浏览 • 1回复 待解决
如何跳转设置—应用详情页
2902浏览 • 1回复 待解决
HarmonyOS 跳转华为应用商店详情页
2879浏览 • 1回复 待解决
CustomDialog如何实现半模态详情页效果
2576浏览 • 1回复 待解决
列表项添加点击跳转详情页功能
265浏览 • 0回复 待解决
如何解决webview离线加载白屏问题
2696浏览 • 1回复 待解决
如何解决webview loaddata白屏问题
2289浏览 • 1回复 待解决
鸿蒙优化,如何检测线上
676浏览 • 0回复 待解决
HarmonyOS WebView加载H5
1253浏览 • 1回复 待解决
如何跳转到设置中应用详情页
3367浏览 • 1回复 待解决
HarmonyOS 应用市场详情页面地址
939浏览 • 1回复 待解决