HarmonyOS Scroll使用onTouch如何判断到最后定点后,依然是有下拉动作

使用Scroll手势下拉刷新界面,如何判断下拉式在最上面,这个时候需要调用接口刷新界面

HarmonyOS
2024-12-24 16:34:57
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

可以使用refresh与scroll嵌套使用,可以参考该链接 https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-refresh-V5

@Entry
@Component
struct RefreshExample {
  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  @State isRefreshing: boolean = false
  scroller: Scroller = new Scroller()

  build() {
    Column() {
      Refresh({ refreshing: $$this.isRefreshing }) {
        Scroll() {
          Column() {
            List() {
              ForEach(this.arr, (item: number) => {
                ListItem() {
                  Text('' + item)
                }.height(100).width('100%')
              })
            }
            .divider({ strokeWidth: 0.5, color: Color.Red })
            .width('100%')
            .height('100%')
            .backgroundColor('#FFDDFF')
            .nestedScroll({
              scrollForward: NestedScrollMode.PARENT_FIRST,
              scrollBackward: NestedScrollMode.SELF_FIRST
            })

            Text('我是scroll').height(100)

          }
        }.width('100%').height('100%').backgroundColor('#FFFFFF')
        .nestedScroll({
          scrollForward: NestedScrollMode.PARENT_FIRST,
          scrollBackward: NestedScrollMode.SELF_FIRST
        })

      }
      .onRefreshing(() => {
        setTimeout(() => {
          this.isRefreshing = !this.isRefreshing
        }, 2000)
      })
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).justifyContent(FlexAlign.Center)
  }
}
  • 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.

或者可以参考对应三方库的实现 https://gitee.com/openharmony-sig/PullToRefresh

分享
微博
QQ
微信
回复
2024-12-24 18:20:06
相关问题
onTouch事件是否可以判断滑动方向
2997浏览 • 1回复 待解决
如何判断当前使用哪个sim卡流量
2965浏览 • 1回复 待解决
Flutter 如何判断HarmonyOS环境
1063浏览 • 1回复 待解决