HarmonyOS Tabs组件滑动到边缘的时候如何禁用滑动效果?现在滑动到边缘了,还能继续画出来一段距离

HarmonyOS
2024-12-24 17:27:46
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

UX标准所有滑动都应有过界回弹效果,tabs组件边缘滑动效果是符合UX标准的。禁止滑动的话,解决方案可以给边缘tabContent添加手势。

示例:

struct TabPage1 {
  @State fontColor: string = '#182431'
  @State selectedFontColor: string = '#007DFF'
  @State currentIndex: number = 0
  private controller: TabsController = new TabsController()
  private panOption1: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Right })
  private panOption2: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Left })

  @Builder tabBuilder(index: number, name: string) {
    Column() {
      Text(name)
        .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
        .fontSize(16)
        .fontWeight(this.currentIndex === index ? 500 : 400)
        .lineHeight(22)
        .margin({ top: 17, bottom: 7 })
      Divider()
        .strokeWidth(2)
        .color('#007DFF')
        .opacity(this.currentIndex === index ? 1 : 0)
    }.width('100%')
  }

  build() {
    Column() {
      Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#00CB87')
        }.tabBar(this.tabBuilder(0, 'green'))
        // 左右拖动触发该手势事件
        .gesture(
          PanGesture(this.panOption1)
            .onActionStart((event?: GestureEvent) => {
              console.info('Pan start')
            })
            .onActionUpdate((event?: GestureEvent) => {
              if (event) {
              }
            })
            .onActionEnd(() => {
              console.info('Pan end')
            })
        )

        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#007DFF')
        }.tabBar(this.tabBuilder(1, 'blue'))

        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#FFBF00')
        }.tabBar(this.tabBuilder(2, 'yellow'))

        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#E67C92')
        }.tabBar(this.tabBuilder(3, 'pink'))

        // 左右拖动触发该手势事件

        .gesture(
          PanGesture(this.panOption2)
            .onActionStart((event?: GestureEvent) => {
              console.info('Pan start')
            })
            .onActionUpdate((event?: GestureEvent) => {
              if (event) {
              }
            })
            .onActionEnd(() => {
              console.info('Pan end')
            })
        )
      }

      .vertical(false)
      .barMode(BarMode.Fixed)
      .barWidth(360)
      .barHeight(56)
      .animationDuration(400)
      .onChange((index: number) => {
        this.currentIndex = index
      })
      .width(360)
      .height(296)
      .margin({ top: 52 })
      .backgroundColor('#F1F3F5')
    }.width('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.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
分享
微博
QQ
微信
回复
2024-12-24 18:24:09
相关问题
HarmonyOS 从屏幕最左侧边缘滑动
572浏览 • 1回复 待解决
Scroll初始时自动滚动一段距离
1681浏览 • 1回复 待解决
Tabs滑动距离问题有哪些?
1308浏览 • 1回复 待解决
如何监听List组件滑动距离
3419浏览 • 1回复 待解决
监听pdf是否已经滑动到最底部失败
2203浏览 • 1回复 待解决