鸿蒙实现右滑加载更多

dart 复制代码
@Entry
@Component
struct Index {
  build() {
    Stack({ alignContent: Alignment.Start }) {
      TabRightMore({ totalSize: 4 }) {
        TabContent() {
          Column().width('100%').height('100%').backgroundColor(Color.Red)
        }

        TabContent() {
          Column().width('100%').height('100%').backgroundColor(Color.Blue)
        }

        TabContent() {
          Column().width('100%').height('100%').backgroundColor(Color.Yellow)
        }

        TabContent() {
          Column().width('100%').height('100%').backgroundColor(Color.Black)
        }
      }
    }
    .height('100%')
    .width('100%')
  }
}

@ComponentV2
struct TabRightMore {
  @Require @Param totalSize: number = 0
  private innerSelectedIndex = 0
  private listScroller: ListScroller = new ListScroller()
  private LAST_INDEX = this.totalSize - 1

  @Monitor('totalSize')
  watchTotalSize() {
    this.LAST_INDEX = this.totalSize - 1
  }

  @Builder
  closerBuilder() {
  }

  // 使用父组件的尾随闭包{}(@Builder装饰的方法)初始化子组件@BuilderParam
  @BuilderParam closer: () => void = this.closerBuilder;

  build() {
    Stack({ alignContent: Alignment.Start }) {
      List({scroller: this.listScroller}) {
        ListItem() {
          Tabs() {
            this.closer()
          }
          .animationDuration(0)
          .edgeEffect(EdgeEffect.None)
          .onAnimationStart((index: number, targetIndex: number) => {
            console.info('ets onGestureRecognizerJudgeBegin child:' + targetIndex)
            this.innerSelectedIndex = targetIndex
          })
          .onGestureRecognizerJudgeBegin((event: BaseGestureEvent, current: GestureRecognizer, others: Array<GestureRecognizer>): GestureJudgeResult => { // 在识别器即将要成功时,根据当前组件状态,设置识别器使能状态
            if (current) {
              let target = current.getEventTargetInfo();
              if (target && current.isBuiltIn() && current.getType() == GestureControl.GestureType.PAN_GESTURE) {
                let panEvent = event as PanGestureEvent;
                if (panEvent && panEvent.velocityX < 0 && this.innerSelectedIndex === this.LAST_INDEX) { // 内层Tabs滑动到尽头
                  return GestureJudgeResult.REJECT;
                }
                if (panEvent && panEvent.velocityX > 0 && this.innerSelectedIndex === 0) { // 内层Tabs滑动到开头
                  return GestureJudgeResult.REJECT;
                }
              }
            }
            return GestureJudgeResult.CONTINUE;
          }, true)
          .barHeight(0)
          .barWidth(0)
          .backgroundColor(Color.Gray)
          .width('100%')
          .height('100%')
        }

        ListItem() {
          Column()
            .backgroundColor(Color.Orange)
            .height('100%')
            .width(100)
        }
      }
      .listDirection(Axis.Horizontal)
      .width('100%')
      .height(200)
      .edgeEffect(EdgeEffect.None)
      .scrollBar(BarState.Off)
      .onTouch((event) => {
        if (event.type === TouchType.Down) {
          console.log('Index000 TouchType.Down')
        } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
          console.log('Index000 TouchType.Up Cancel ' + this.listScroller.currentOffset().xOffset)
          this.listScroller.scrollTo({ xOffset: 0, yOffset: 0, animation: true })
        }
      })
    }
    .height('100%')
    .width('100%')
  }
}
相关推荐
ChinaDragonDreamer8 天前
HarmonyOS:知识点总结(一)
harmonyos·鸿蒙
加农炮手Jinx9 天前
Flutter for OpenHarmony 实战:JWT — 构建安全的无状态认证中心
网络·flutter·华为·harmonyos·鸿蒙
雷帝木木9 天前
Flutter for OpenHarmony:Flutter 三方库 money2 — 坚不可摧的鸿蒙金融核心组件
网络·flutter·http·华为·金融·harmonyos·鸿蒙
特立独行的猫a9 天前
uniapp-x的HarmonyOS鸿蒙应用开发:tabbar底部导航栏的实现
华为·uni-app·harmonyos·鸿蒙·uniapp-x
●VON9 天前
HarmonyOS应用开发实战(基础篇)Day10 -《鸿蒙网络请求实战》
网络·学习·华为·harmonyos·鸿蒙·von
●VON10 天前
HarmonyOS应用开发实战(基础篇)Day08-《构建布局详解上》
华为·harmonyos·鸿蒙·von
加农炮手Jinx12 天前
Flutter for OpenHarmony 实战:疯狂头像 App(三)— 复合动画与交互反馈 — 让 UI 跃动起来
flutter·ui·交互·harmonyos·鸿蒙
_waylau13 天前
鸿蒙架构师修炼之道-架构师设计思维特点
华为·架构·架构师·harmonyos·鸿蒙·鸿蒙系统
Betelgeuse7613 天前
【Flutter For OpenHarmony】 项目结项复盘
华为·交互·开源软件·鸿蒙
ITUnicorn14 天前
【HarmonyOS 6】进度组件实战:打造精美的数据可视化
华为·harmonyos·arkts·鸿蒙·harmonyos6