HarmonyOS tab组件滑到最后一个index的时候,可以关闭回弹效果吗

tab组件滑倒最后一个index的时候,可以关闭回弹效果吗

HarmonyOS
2024-12-20 15:28:51
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

边缘tab继续滑动可以通过给TabContent添加手势进行限制。参考方案如下: 最左侧的TabContent添加.gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Right }))),限制组件内置的右滑动。 最右侧的TabContent添加.gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Left }))),限制组件内置的左滑动。参考demo:

@Entry
@Component
struct TabsExample {
  private controller: TabsController = new TabsController();

  build() {
    Column() {
      Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
        TabContent() {
          Column()
            .width('100%')
            .height('100%')
            .backgroundColor(Color.Green)
        }
        .tabBar('green')
        .gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Right })))

        TabContent() {
          Column()
            .width('100%')
            .height('100%')
            .backgroundColor(Color.Blue)
        }
        .tabBar('blue')
        .gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Left })))

        // ...

      }
      .barMode(BarMode.Scrollable)
      .barWidth('100%')
      .barHeight(60)
      .width('100%')
      .height('100%')
      .backgroundColor(0xF5F5F5)
    }
  }
}
分享
微博
QQ
微信
回复
2024-12-20 18:47:46
相关问题
如何关闭Swiper组件回弹效果
1700浏览 • 1回复 待解决
HarmonyOS Tab指定默认Index
788浏览 • 1回复 待解决
HarmonyOS list最后一个显示不出来
1187浏览 • 1回复 待解决