HarmonyOS Web嵌套滚动体验差

商品详情页,嵌套滚动的时候父容器往下滑的过程中,惯性传不到WebView里面,但是从webView往上滑的时候,惯性能传递到父布局。

HarmonyOS
2024-12-17 15:08:59
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280
import web_webview from '@ohos.web.webview';

@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: "https://www.huawei.com/s?id=1778113237500106256&wfr=spider&for=pc",
        }).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;
            }
          })
      }.width("100%")
    }
    .onTouch((event: TouchEvent) => {
      if (event.type == TouchType.Down) {
        this.scrollTouchDown = true;
      } else if (event.type == TouchType.Up) {
        this.scrollTouchDown = false;
      }
    })
    .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%')
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-17 16:33:54
相关问题
HarmonyOS 嵌套滚动冲突
863浏览 • 1回复 待解决
如何实现嵌套滚动技术
2039浏览 • 1回复 待解决
基于webView的嵌套滚动
1018浏览 • 1回复 待解决
HarmonyOS Scroll嵌套web手势冲突
673浏览 • 1回复 待解决
HarmonyOS web组件滚动方向判断
538浏览 • 1回复 待解决
HarmonyOS list 嵌套web滑动切换问题
1193浏览 • 1回复 待解决
HarmonyOS List和Web嵌套问题
665浏览 • 1回复 待解决
HarmonyOS scroll嵌套多个web,显示问题
799浏览 • 1回复 待解决
Grid嵌套滚动问题有知道的吗?
3582浏览 • 1回复 待解决
页面和列表嵌套滚动,实现列表吸顶
2245浏览 • 1回复 待解决
HarmonyOS Scroll+web+list的嵌套滑行
616浏览 • 1回复 待解决